Install mysql-5.7.20 in RPM mode under CentOS7

1. Prepare 4 documents
mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
2. Because MariaDB is installed by default in centos7, it needs to be uninstalled first, which is critical
> rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
> rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
> rpm -e --nodeps mariadb-5.5.52-1.el7.x86_64
> rpm -qa|grep mariadb #Check whether the uninstallation is successful
 
3. Install as root user in the order of 1. The mysql user will be automatically created during installation
 
4. Initialize mysql
> mysqld --initialize --user=mysql
 
5. View the /etc/my.cnf file (used to locate the log log during initialization, the log records the initialization password)
> vi /etc/my.cnf
........
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
........
 
View initialization password
> vi /var/log/mysqld.log
......
A temporary password is generated for root@localhost: UloEtAbnt2*5
.......
(密码:UloEtAbnt2*5)
 
6、启动MySQL
> systemctl start mysqld
 
7、登陆mysql用户
> mysql -u root -p
输入密码 UloEtAbnt2*5(P.S. 见日志)
 
更改密码为mysql:
mysql> set password=password('mysql');
 
8、修改用户可以远程连接
#先查看有哪些用户
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
host为localhost代表只能本地访问。要root用户可以远程访问,可以把host改为%
> update user set host='%' where user='root';
> flush privileges; #刷新后才生效
增加用户:
> grant all privileges on *.* to 'admin'@'%' identified by 'admin123' with grant option; #增加admin用户,密码为admin123,允许可以远程访问

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326144443&siteId=291194637