Centos6.5 安装 MySql5.7

前端之家收集整理的这篇文章主要介绍了Centos6.5 安装 MySql5.7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.检查系统是否已存在旧版MysqL,并卸载。

  1. # yum list installed | grep MysqL
  2. MysqL-libs.x86_64 5.1.71-1.el6 @anaconda-CentOS-201311272149.x86_64/6.5
  3. # yum -y remove MysqL-libs.x86_64

MysqL5.7安装包可以去官网下载https://dev.MysqL.com/downloads/repo/yum/

安装MysqL5.7,遇到选项输入y就行了。或者安装的时候添加 -y 参数

  1. # yum install MysqL57-community-release-el6-8.noarch.rpm
  1. # ls /etc/yum.repos.d
  2. CentOS-Base.repo CentOS-Media.repo MysqL-community.repo
  3. CentOS-Debuginfo.repo CentOS-Vault.repo MysqL-community-source.repo
  1. # yum install MysqL-community-server

网络状况不好时需要耐心等待一会儿。

安装完成,启动MysqL

  1. # service MysqLd start
  2. Initializing MysqL database: [ OK ]
  3. Installing validate password plugin: [ OK ]
  4. Starting MysqLd: [ OK ]

查看MysqL 密码

  1. # grep "password" /var/log/MysqLd.log
  2. 2017-03-16T14:39:00.743966Z 1 [Note] A temporary password is generated for root@localhost: F7u?yhf,#LR6
  3. 2017-03-16T14:39:06.760164Z 0 [Note] Execution of init_file '/var/lib/MysqL/install-validate-password-plugin.XkuhjP.sql' started.
  4. 2017-03-16T14:39:06.809413Z 0 [Note] Execution of init_file '/var/lib/MysqL/install-validate-password-plugin.XkuhjP.sql' ended.
  5. 2017-03-16T14:39:08.625174Z 0 [Note] Shutting down plugin 'sha256_password'
  6. 2017-03-16T14:39:08.625190Z 0 [Note] Shutting down plugin 'MysqL_native_password'
  7. 2017-03-16T14:39:13.324745Z 3 [Note] Access denied for user 'UNKNOWN_MysqL_USER'@'localhost' (using password: NO)

修改密码 无密码进入MysqL控制台

  1. # vim /etc/my.cnf

在/etc/my.cnf [MysqLd] 后添加

  1. skip-grant-tables=1

重启 msyql

  1. # service MysqLd restart
  2. Stopping MysqLd: [ OK ]
  3. Starting MysqLd: [ OK ]

进入MysqL控制台修改密码

  1. # MysqL -uroot
  2. Welcome to the MysqL monitor. Commands end with ; or \g.
  3. Your MysqL connection id is 5
  4. Server version: 5.7.17 MysqL Community Server (GPL)
  5.  
  6. Copyright (c) 2000,2016,Oracle and/or its affiliates. All rights reserved.
  7.  
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11.  
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13.  
  14. MysqL>

切换至MysqL数据库

  1. MysqL> use MysqL;
  2. Reading table information for completion of table and column names
  3. You can turn off this feature to get a quicker startup with -A
  4.  
  5. Database changed

查看user表中的信息

  1. MysqL> select user,host,authentication_string from user;
  2. +-----------+-----------+-------------------------------------------+
  3. | user | host | authentication_string |
  4. +-----------+-----------+-------------------------------------------+
  5. | root | localhost | *39820588410CB0B7DDA4AD6595C19A92C7B52B52 |
  6. | MysqL.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  7. +-----------+-----------+-------------------------------------------+

修改root@localhost 密码

  1. MysqL> update user set authentication_string=password('123456') where user='root' and host='localhost';
  2. Query OK,1 row affected,1 warning (0.05 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 1

查看并退出控制台

  1. MysqL> select user,authentication_string from user;
  2. +-----------+-----------+-------------------------------------------+
  3. | user | host | authentication_string |
  4. +-----------+-----------+-------------------------------------------+
  5. | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
  6. | MysqL.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  7. +-----------+-----------+-------------------------------------------+
  8. 2 rows in set (0.01 sec)
  9.  
  10. MysqL> exit;
  11. Bye

用新密码登录

  1. # MysqL -uroot -p
  2. Enter password:

输入密码,成功登录

  1. # MysqL -uroot -p
  2. Enter password:
  3. Welcome to the MysqL monitor. Commands end with ; or \g.
  4. Your MysqL connection id is 6
  5. Server version: 5.7.17 MysqL Community Server (GPL)
  6.  
  7. Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved.
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14.  
  15. MysqL>

对安全无要求的测试场景可以设置skip-grant-tables=1,不然则注释skip-grant-tables

授予远程访问权限

  1. MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
  2. ERROR 1290 (HY000): The MysqL server is running with the --skip-grant-tables option so it cannot execute this statement

出现以上问题可以刷新一下再执行

  1. MysqL> flush privileges;
  2. Query OK,0 rows affected (0.06 sec)
  3.  
  4. MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
  5. Query OK,0 rows affected,1 warning (0.00 sec)

查看新添加的权限

  1. MysqL> select user,authentication_string from user;
  2. +-----------+-----------+-------------------------------------------+
  3. | user | host | authentication_string |
  4. +-----------+-----------+-------------------------------------------+
  5. | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
  6. | MysqL.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
  7. | root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
  8. +-----------+-----------+-------------------------------------------+
  9. 3 rows in set (0.01 sec)

猜你在找的CentOS相关文章