1.检查系统是否已存在旧版mysql,并卸载。
# yum list installed | grep mysql
mysql-libs.x86_64 5.1.71-1.el6 @anaconda-CentOS-201311272149.x86_64/6.5
# yum -y remove mysql-libs.x86_64
mysql5.7安装包可以去官网下载 https://dev.mysql.com/downloads/repo/yum/
安装mysql5.7,遇到选项输入y就行了。或者安装的时候添加 -y 参数
# yum install mysql57-community-release-el6-8.noarch.rpm
# ls /etc/yum.repos.d
CentOS-Base.repo CentOS-Media.repo mysql-community.repo
CentOS-Debuginfo.repo CentOS-Vault.repo mysql-community-source.repo
# yum install mysql-community-server
网络状况不好时需要耐心等待一会儿。
安装完成,启动mysql
# service mysqld start
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]
查看mysql 密码
# grep "password" /var/log/mysqld.log
2017-03-16T14:39:00.743966Z 1 [Note] A temporary password is generated for root@localhost: F7u?yhf,#LR6
2017-03-16T14:39:06.760164Z 0 [Note] Execution of init_file '/var/lib/mysql/install-validate-password-plugin.XkuhjP.sql' started.
2017-03-16T14:39:06.809413Z 0 [Note] Execution of init_file '/var/lib/mysql/install-validate-password-plugin.XkuhjP.sql' ended.
2017-03-16T14:39:08.625174Z 0 [Note] Shutting down plugin 'sha256_password'
2017-03-16T14:39:08.625190Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-03-16T14:39:13.324745Z 3 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
修改密码 无密码进入mysql控制台
# vim /etc/my.cnf
在/etc/my.cnf [mysqld] 后添加
skip-grant-tables=1
重启 msyql
# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
进入mysql控制台修改密码
# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
切换至mysql数据库
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
查看user表中的信息
mysql> select user,host,authentication_string from user;
+-----------+-----------+-------------------------------------------+
| user | host | authentication_string |
+-----------+-----------+-------------------------------------------+
| root | localhost | *39820588410CB0B7DDA4AD6595C19A92C7B52B52 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-----------+-------------------------------------------+
mysql> update user set authentication_string=password('123456') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 1
查看并退出控制台
mysql> select user,host,authentication_string from user;
+-----------+-----------+-------------------------------------------+
| user | host | authentication_string |
+-----------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-----------+-------------------------------------------+
2 rows in set (0.01 sec)
mysql> exit;
Bye
用新密码登录
# mysql -uroot -p
Enter password:
输入密码,成功登录
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
对安全无要求的测试场景可以设置 skip-grant-tables=1,不然则注释skip-grant-tables
授予远程访问权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
出现以上问题可以刷新一下再执行
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
查看新添加的权限
mysql> select user,host,authentication_string from user;
+-----------+-----------+-------------------------------------------+
| user | host | authentication_string |
+-----------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-----------+-------------------------------------------+
3 rows in set (0.01 sec)