1.选择版本
2.安装步骤
-
上传软件包到linux上
-
对mysql压缩包解压
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
- 移动mysql解压好的文件到 /usr/local/mysql下
mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql
-
检查mysql组和用户是否存在,如果没有则创建,创建一个mysql用户并更改/usr/local/mysql目录权限(用户和组)
cat /etc/group|grep mysql #查看 groupadd mysql useradd -r -g mysql mysql
-
在/usr/local/mysql下创建 data目录
[root@localhost mysql]# mkdir data
-
将/usr/local/mysql 的拥有者和所属组修改为mysql
[root@localhost mysql]# chown -R mysql.mysql /usr/local/mysql
-
在/usr/local/mysql/support-files 目录下创建my_default.cnf
[root@localhost mysql]# vim support-files/my_default.cnf #################复制下列文字########################################### [mysqld] #设置mysql的安装目录 basedir = /usr/local/mysql #设置mysql数据库的数据存放目录 datadir = /usr/local/mysql/data #设置端口 port = 3306 socket = /tmp/mysql.sock #设置字符集 character-set-server=utf8 #日志存放目录 log-error = /usr/local/mysql/data/mysqld.log pid-file = /usr/local/mysql/data/mysqld.pid #允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE) sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION #ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
-
拷贝 my_default.cnf文件
[root@localhost support-files]# cp my_default.cnf /etc/my.cnf cp:是否覆盖"/etc/my.cnf"? y
-
初始化mysql
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
-
安装libaio插件
[root@localhost mysql]# yum install libaio
-
初始化完成后查看日志 最后出现在localhost:后皆为初始密码
[root@localhost mysql]# cat /usr/local/mysql/data/mysqld.log
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H3n3B9Uw-1587203828709)(C:\Users\admin\AppData\Local\Temp\1587194499701.png)]
-
把启动脚本放到初始化目录
```shell
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
```
-
启动mysql
[root@localhost mysql]# service mysql start Starting MySQL. SUCCESS!
-
进入mysql并更改密码,
[root@localhost mysql]# cd /usr/local/mysql [root@localhost mysql]# ./bin/mysql -u root -p mysql> set password=password('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> grant all privileges on *.* to root@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (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> update user set host='%' where user = 'root'; ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' mysql> select host,user from user where user='root'; +-----------+------+ | host | user | +-----------+------+ | % | root | | localhost | root | +-----------+------+ 2 rows in set (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
-
退出,重启mysql生效
[root@localhost mysql]# service mysql restart Shutting down MySQL.... SUCCESS! Starting MySQL. SUCCESS!