CentOS 7安装MySQL 8.0教程
在centos7中已经将mysql从yum应用列表中移除,并使用mariadb代替,所以直接通过yum install mysql-server安装时会提示没有可用软件包mysql-server。在centos7中安装mysql需要重新添加mysql的存储库。
1. 下载MySQL提供的CentOS7的yum源
方式一、官网下载
方式二、CentOS命令下载
[root@localhost ~]# curl https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm > centos7.mysql.rpm
curl是CentOS系统自带的
2. 安装yum源
[root@localhost ~]# yum install centos7.mysql.rpm
3. 安装MySQL 8.0
[root@localhost ~]# yum install mysql-community-server
4. 解决“安装mysql提示公钥尚未安装”
mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm 的公钥尚未安装
运行如下命令
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
再安装mysql [root@localhost ~]# yum install mysql-community-server
mysql安装成功~~~
启动mysql [root@localhost ~]# systemctl start mysqld
启动/停止/重启mysql:
# 启动 [root@localhost ~]# systemctl start mysqld 或 [root@localhost ~]# service mysqld start # 重启 [root@localhost ~]# systemctl restart mysqld 或 [root@localhost ~]# service mysqld restart # 停止 [root@localhost ~]# systemctl stop mysqld 或 [root@localhost ~]# service mysqld stop
设置开机启动mysql [root@localhost ~]# systemctl enable mysqld
5. 初始化配置
1)查看初始密码
[root@localhost ~]# cat /var/log/mysqld.log | grep "password"
2)安全初始化
[root@localhost ~]# mysql_secure_installation
Change the password for root ? 更改root用户的密码? Do you wish to continue with the password provided?是否继续使用提供的密码? Remove anonymous users? 删除匿名用户?(建议选择Y 删除) Disallow root login remotely?禁止root远程登录?(默认不允许远程登录 ) Remove test database and access to it?是否移除测试数据库(初学者建议先不移除N) Reload privilege tables now?是否现在重新加载特权表?(当我们更改了mysql用户相关的信息之后,建议重新加载Y)
6. 基本使用
1)登录mysql
[root@localhost ~]# mysql -u root -p
2)退出mysql
mysql> exit
