原文:http://www.th7.cn/db/mysql/201612/218745.shtml
1.mysql5.7.17安装在/usr/local/mysql目录里面,也可以安装在其他地方 (安装包最好与Linux系统一样,eg;32位的就是“mysql-5.7.17-linux-glibc2.5-i686.tar.gz”,官网可下载)
mkdir /usr/local/mysql
2.解压并复制
- tar -xvf mysql-5.7.17-linux-glibc2.5-i686.tar.gz
- mv mysql-5.7.17-linux-glibc2.5-i686.tar.gz/* /usr/local/mysql/
3.创建data目录(很重要!)
- mkdir /usr/local/mysql/data
4.创建mysql用户和修改权限
- groupadd mysql
- chown -R mysql.mysql /usr/local/mysql/
5.初始化数据
- [root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
- 2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
- 2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
- 2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
- 2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
- 2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
6. 复制配置文件到 /etc/my.cnf
- cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
7. mysql的服务脚本放到系统服务中
- 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
8.启动mysql
- service mysqld start
- ps -ef #查看是启动
9.查看初始化自动生成的密码: cat /root/.mysql_secret (记住并复制下来,等会登陆mysql需要)
10.进入mysql:bin/mysql -uroot -p (把刚刚复制的密码粘贴上来)
11.登录后重置root密码
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)