Centos7 安装mysql 5.7.20
2018-06-22 本文已影响9人
Martain
1、下载repo源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
2、相关文件
配置文件:/etc/my.cnf
注:如果要开发远程连接 在配置文件中添加 bind-address = 0.0.0.0
3、启动mysql
service mysqld restart
4、获取默认随机密码
grep "password" /var/log/mysqld.log
如:
[root@VM_64_69_centos src]# grep "password" /var/log/mysqld.log
2018-06-22T14:01:17.280254Z 1 [Note] A temporary password is generated for root@localhost: uakpaTVah8(e
5、利用该密码登录
6、修改MySql的密码:
mysql> set password for 用户名@localhost = password('新密码');
例如:mysql> set password for root@localhost = password('123');
7、开启远程附加操作
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 user,host from user
-> ;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> quit
Bye
8、记得重启Mysql
service mysqld restart