1.下载安装包
https://dev.mysql.com/downloads/file
2.解压文件,复制到/usr/local
tar -xvf mysql-5.7.20-linux-glibc2.12-x86_64.tar 解压后有有两个文件:mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz,mysql-test-5.7.20-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 解压后文件名为:mysql-5.7.20-linux-glibc2.12-x86_64,
mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql 重命名
cp mysql /usr/local/ -r 复制
cd /usr/local 进入安装文件夹
3. 增加用户
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# cd ..
[root@localhost local]# chown -R mysql mysql/
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# cd mysql/
[root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2017-12-18 15:38:29 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-12-18 15:38:31 [WARNING] The bootstrap log isn't empty:
2017-12-18 15:38:31 [WARNING] 2017-12-18T07:38:29.824248Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-12-18T07:38:29.835981Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-12-18T07:38:29.836022Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
4.安装
[root@localhost mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
cp: 无法获取"./support-files/my-default.cnf" 的文件状态(stat): 没有那个文件或目录
当报这个错误的时候增加一个my-default.cnf 文件。内容配置如下:
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
然后在执行:
[root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@localhost mysql]# ll
[root@localhost mysql]# cd bin
[root@localhost bin]# ./mysqld_safe --user=mysql &
[1] 8475
[root@localhost bin]# Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
2017-12-18T07:47:16.901751Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@localhost bin]#
[root@localhost bin]#
[root@localhost bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2017-12-18T07:47:43.297782Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
SUCCESS!
Starting MySQL. SUCCESS!
[1]+ 完成 ./mysqld_safe --user=mysql
5.初始化密码,以及添加远程访问
[root@localhost bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-12-18 15:38:29
(Af_i4,i(.E;
[root@localhost bin]# ./mysql -uroot -p
Enter password:
mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('yangdi');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.20 |
+-----------+
1 row in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>quit;
[root@localhost bin]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
// 查看mysql是否启动成功
[root@localhost bin]# ps -ef |grep mysql
设置开机启动
6.使用navicate 连接,检查防火墙状态!!!!