Centos7安装mysql8.0

Centos7安装mysql8.0

转载至 原文章地址

如果你已经安装了mysql,需要先卸载,卸载请参考:

Centos7 完全卸载mysql

检查 MariaDB 是否安装

yum list installed|grep mariadb

image.png

卸载全部 MariaDB 相关

yum-yremovemariadb*

image.png

数据准备

下载mysql安装包

[root@localhost~]# cd/usr/local/src/

[root@localhost src]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

下载完后可以目录中看到:

image.png

安装mysql源

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

image.png

检查 MySQL 的 YUM 源是否安装成功

yum repolist enabled | grep "mysql.*-community.*"

image.png

查看 MySQL 版本

yum repolist all | grep mysql

image.png

安装 MySQL

yum install mysql-community-server

image.png

启动mysql服务

systemctl start mysqld附加命令查看MySQL状态 systemctl status mysqld关闭MySQL服务 systemctl stop mysqld重启MySQL服务 systemctl restart mysqld

image.png

查看自动生成的临时密码

grep 'temporary password' /var/log/mysqld.log

image.png

这个密码先自己保存下

登录mysql

使用刚才生成的临时密码

mysql -uroot -p

image.png

这时候对数据的操作会报错,必须先改密码

image.png

mysql8.0修改密码和以往不同,我看过别的教程,修改成功后,无法使用该密码进行登录,正确方式如下(引号后面是密码)

密码需要包含大小写字母、数字、符号长度也不能过短,暂时先弄一个很长的,一会再改。

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "#20as3SElk3@wwerwer232342432342343223243sdfasfafasdsds0ew98";

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "#20as3SElk3@wwerwer232342432342343223243sdfasfafasdsds0ew98";

刷新

FLUSH privileges;

此时我们退出,重新登录看看效果

(输入密码我们用复制的,在xshell中操作)

mysql>quit;Bye[root@localhostsrc]# mysql-uroot-pEnter password:Welcome to the MySQL monitor.Commands endwith;or \g.Your MySQL connection idis9Server version:8.0.17MySQL Community Server-GPLCopyright(c)2000,2019,Oracle and/or its affiliates.All rights reserved.Oracleisa registered trademark of Oracle Corporation and/or itsaffiliates.Other names may be trademarks of their respectiveowners.Type'help;'or'\h'forhelp.Type'\c'to clear the current input statement.mysql>

可以登录!

设置安全策略

因为要把刚才的密码改的简单一点,这里需要先修改安全策略,mysql8.0修改安全策略的命令和5.7不同,具体如下

先选择数据库:use mysql;5.7语法:setglobalvalidate_password_policy=0;setglobalvalidate_password_length=1;8.0语法:setglobalvalidate_password.policy=0;setglobalvalidate_password.length=1;最后都要刷新:FLUSHprivileges;

修改密码

mysql>use mysql;Readingtable informationforcompletion of table and column namesYoucan turn offthisfeature togeta quicker startup with-ADatabasechangedmysql>ALTERUSER'root'@'localhost'IDENTIFIEDWITHmysql_native_password BY"123456";QueryOK,0rows affected(0.00sec)mysql>flush privileges;QueryOK,0rows affected(0.00sec)

退出重新登录

输入刚才修改的密码

mysql>quit;Bye[root@localhostsrc]# mysql-uroot-pEnter password:Welcome to the MySQL monitor.Commands endwith;or \g.Your MySQL connection idis11Server version:8.0.17MySQL Community Server-GPLCopyright(c)2000,2019,Oracle and/or its affiliates.All rights reserved.Oracleisa registered trademark of Oracle Corporation and/or itsaffiliates.Other names may be trademarks of their respectiveowners.Type'help;'or'\h'forhelp.Type'\c'to clear the current input statement.mysql>

设置远程访问

mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';Query OK, 0 rows affected (2.30 sec)mysql> GRANT ALL ON *.* TO 'root'@'%';Query OK, 0 rows affected (0.01 sec)mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.03 sec)mysql>

开启防火墙

[root@localhost src]# firewall-cmd--zone=public--add-port=3306/tcp--permanentsuccess[root@localhost src]# firewall-cmd--reloadsuccess

你可能感兴趣的:(Centos7安装mysql8.0)