CentOS7下以RPM方式安装mysql-5.7.20 mysqlcentos75.7.20
程序员文章站
2024-01-06 20:04:16
...
1、准备4个文件
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、因为centos7默认安装了MariaDB,需要先卸载,很关键
> 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 #查看是否卸载成功
3、用root用户按1.的顺序安装,安装的时候会自动创建mysql用户
4、初始化mysql
> mysqld --initialize --user=mysql
5、查看/etc/my.cnf文件(用于定位初始化时log日志,日志中记录了初始化的密码)
> vi /etc/my.cnf
........
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
........
查看初始化密码
> 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 | 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,允许可以远程访问
推荐阅读
-
CentOS7下以RPM方式安装mysql-5.7.20 mysqlcentos75.7.20
-
CentOS7下以RPM方式安装mysql-5.7.20 mysqlcentos75.7.20
-
MySQL之—CentOS下以RPM方式安装MySQL5.5详细介绍
-
CentOS7上以rpm方式安装JDK8
-
Linux系统下以RPM方式如何安装mysql-5.7.9
-
CentOS7上以rpm方式安装JDK8
-
CentOS/RHEL6+下以RPM方式安装MySQL5.5_MySQL
-
CentOS下以RPM方式安装MySQL 5.5
-
Linux系统下以RPM方式如何安装mysql-5.7.9
-
CentOS/RHEL6+下以RPM方式安装MySQL5.5_MySQL