1、需要mysql-linux安装包
本次使用mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz进行安装
2、将此安装包上传至linux服务器
上传路径为:/usr/local
3、解压mysql
输入命令:tar zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
4、复制mysql到/usr/local/mysql文件夹内(注意mysql-5.7.17-linux-glibc2.5-x86_64此文件夹名称不会变,复制粘帖后的会被改名为mysql)
输入命令:cp mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql -r
5、添加系统mysql组和mysql用户
输入命令:groupadd mysql和useradd -r -g mysql mysql
6、进入安装mysql软件目录:执行命令
输入命令: cd /usr/local/mysql
7、修改当前目录拥有者为mysql用户:执行命令
输入命令: chown -R mysql:mysql ./
8、安装数据库之前创建文件夹,这个很重要
输入命令: mkdir /usr/local/mysql/data
9、安装数据库:执行命令
mysql5.7和之前版本不同,很多资料上都是这个命令:../scripts/mysql_install_db --user=mysql,而mysql5.7的mysql_install_db命令是在bin目录下 的并且建议 用 mysqld --initialize命令
mysql5.7之前版本初始化配置表命令:
输入命令: ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
之后版本:
输入命令:./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
若出现 ./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory 的错误;
则是缺少libnuma依赖.我们可以通过安装yum install -y libnuma来解决这个问题
10、复制配置文件到 /etc/my.cnf
输入命令: cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
11、mysql的服务脚本放到系统服务中,然后修改my.cnf文件
输入命令: cp -a ./support-files/mysql.server /etc/init.d/mysqld
编辑文件:vi /etc/my.cnf
//修改my.cnf文件 (vi /etc/my.cnf) # These are commonly set, remove the # and set as required. basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 # server_id = ..... socket = /tmp/mysql.sock character-set-server = utf8 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M
12、启动mysql
输入命令: service mysqld start
13、查看mysql初始密码(记住并复制下来,等会登陆mysql需要)
输入命令: cat /root/.mysql_secret
14、进入mysql:bin/mysql -uroot -p (把刚刚复制的密码粘贴上来)
15、登录后重置root密码
mysql> SET PASSWORD FOR ‘root‘@localhost = PASSWORD(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
16、修改linux防火墙端口,开发3306给外部访问,编辑iptables
输入命令: vi /etc/sysconfig/iptables
添加一句:-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
17、修改mysql配置,允许外部访问:
输入命令: cd /usr/local/mysql/bin
登录mysql数据库命令: ./mysql -uroot -p123456
mysql>use mysql;
mysql>update user set host = ‘%‘ where user = ‘root‘;
18、重启防火墙,重启mysql数据库
输入命令: service iptables restart重启防火墙
输入命令: service mysqld restart重新mysql
19、设置mysql开机启动
查看mysql是否开机启动
# chkconfig --list | grep mysqld
设置开机启动
# chkconfig mysqld on
原文地址:https://www.cnblogs.com/sumuncle/p/9604475.html