联系qq:413607496,大家可以互相讨论一下。
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、安装数据库:执行命令
输入命令: ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
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
//修改my.cnf文件 (vim /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配置,允许外部访问:
登录mysql数据库:mysql -uroot -p123456
mysql>use mysql;
mysql>update user set host = ‘%‘ where user = ‘root‘;
17、重启防火墙,重启mysql数据库
输入命令: service iptables restart 重启防火墙
输入命令: service mysqld restart 重新mysql