微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Centos6.5 安装 MySql5.7

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 |
+-----------+-----------+-------------------------------------------+

修改root@localhost 密码

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,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,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,authentication_string from user;
+-----------+-----------+-------------------------------------------+
| user      | host      | authentication_string                     |
+-----------+-----------+-------------------------------------------+
| root      | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| MysqL.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root      | %         | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-----------+-------------------------------------------+
3 rows in set (0.01 sec)

原文地址:https://www.jb51.cc/centos/378349.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。