- 查看系统版本
[root@JD ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
- 安装源
[root@JD local]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2020-02-13 17:12:10-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.212.229.233
Connecting to repo.mysql.com (repo.mysql.com)|23.212.229.233|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql-community-release-el7-5.noarch.rpm’
100%[===============================================================================================================================================================================================================================================>] 6,140 22.1KB/s in 0.3s
2020-02-13 17:12:12 (22.1 KB/s) - ‘mysql-community-release-el7-5.noarch.rpm’ saved [6140/6140]
[root@JD ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
- 检查安装是否成功
[root@JD mysql]# rpm -Uvh mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
package mysql-community-release-el7-5.noarch is already installed
执行成功后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo及 mysql-community-source.repo
- 开始安装
[root@JD mysql]# yum -y install mysql-community-server
- 启动
[root@JD mysql]# systemctl start mysqld.service
- 设置自动启动
[root@JD mysql]# service mysqld start
- 查看状态
[root@JD mysql]# systemctl status mysqld.service
- 修改/etc/my.cnf vim /etc/my.cnf 配置文件添加skip-grant-tables
- 上述方式不成功时,以参数形式启动
mysqld --skip-grant-tables --user=root &
- 重启
[root@JD mysql]# systemctl restart mysqld.service
- 登录并切换数据库到mysql
[root@JD mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> 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
mysql>
- 修改密码
UPDATE user SET Password = 'new-password' WHERE User = 'root';
或
UPDATE user SET authentication_string = 'new-password' WHERE User = 'root';
- 允许root远程访问
[root@JD ~]# mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'IP' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
- 退出并删掉无密码登录配置、重启数据库