CentOS7.6安装MySQL8.0

增加yum 源

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

安装MySQL8 社区版

由于MySQL yum库有多个版本的多个库配置,你需要在MySQL repo文件中禁用所有库:

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo

然后用以下命令安装

yum --enablerepo=mysql80-community install mysql-community-server

这个时候可能会出现错误 Unable to find a match: mysql-community-server

输入以下解决问题,然后再重新运行安装命令

yum module disable mysql

启动MySQL服务

service mysqld start

获取随机默认root密码

grep "A temporary password" /var/log/mysqld.log

这行命令会输出如下信息

[Note] A temporary password is generated for root@localhost: hjkygMukj5+t783

这个密码是临时命令我们需要拿来配置MySQL_Init

初始化MySQL服务

 mysql_secure_installation

然后会要求你输入root密码 输入通过命令得到密码

Enter password for user root:

这里会要求你输入一个新的密码 密码格式 Test123.

The existing password for the user account root has expired. Please set a new password.

New password:
Re-enter new password:

输入新密码后有一些配置需要配置

You will need to enter the new password for the root‘s account twice. It will prompt for some questions, it is recommended to type yes (y):

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
//是否要删除匿名用户
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
//是否要禁用远程连接

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
//是否要删除测试数据库
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
//刷新用户权限表

重启MySQL服务并设置开机启动MySQL

service mysqld restart
chkconfig mysqld on

连接MySQL服务

mysql -u root -p

输入root密码就可以连接进去了

mysql>

使用SHOW DATABASES 命令查看现有数据库

show databases;

这里会输出

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.05 sec)

那么到了这里,恭喜你正确的在CentOS 7.6上安装了MySQL8.0

# MySQL 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×