centos系统mysql安装

  coredump对于centos系统,安装mysql涉及很多依赖,一般使用rpm包进行安装。本文以centos7.9安装mysql为例,其它centos版本也可参考。

0. 下载mysql安装包

下载网址:
https://dev.mysql.com/downloads/mysql/
需要根据系统版本下载相应的安装包,本文使用centos7.9(x86-64), 因此选择el7版本。
安装包名称: mysql-8.0.33-1.el7.x86_64.rpm-bundle.tar

1. 解压后,依次安装

rpm -ivh mysql-community-common-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.33-1.el8.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-compat-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.33-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.33-1.el7.x86_64.rpm

其它可选安装包:
mysql-community-client-5.7.18-1.el7.x86_64.rpm
mysql-community-devel-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-5.7.18-1.el7.x86_64.rpm
mysql-community-server-5.7.18-1.el7.x86_64.rpm
mysql-community-libs-5.7.18-1.el7.x86_64.rpm
mysql-community-test-5.7.18-1.el7.x86_64.rpm

2. 查看安装状态

$ rpm -qa | grep mysql

mysql-community-client-8.0.33-1.el7.x86_64
mysql-community-server-8.0.33-1.el7.x86_64
mysql-community-libs-8.0.33-1.el7.x86_64
mysql-community-release-el7-5.noarch
mysql-community-libs-8.0.33-1.el8.x86_64
mysql-community-client-plugins-8.0.33-1.el7.x86_64
mysql-community-common-8.0.33-1.el8.x86_64
mysql-community-libs-compat-8.0.33-1.el7.x86_64
mysql-community-icu-data-files-8.0.33-1.el7.x86_64
mysql-community-common-8.0.33-1.el7.x86_64
mysql57-community-release-el7-7.noarch

3. 启动服务

$ systemctl start mysqld

4. 跳过权限验证

登录mysql时报如下错误:
$ mysql
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)

需要更改配置文件来跳过权限验证
在/etc/my.cnf中加上skip-grant-tables, 然后重启

5. 查看密码相关信息

mysql> SHOW variables LIKE ‘validate_password%’;
±-------------------------------------±-------+
| Variable_name | Value |
±-------------------------------------±-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
±-------------------------------------±-------+
7 rows in set (0.34 sec)

6. 更改密码

update user set authentication_string=‘’ where user=‘root’;

flush privileges;

AlTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘hello1abC#’;

7. 恢复密码权限验证

更改密码后,删除/etc/my.cnf中的skip-grant-tables,重启即可

$systemctl restart mysqld

8. 登录

$ mysql -uroot -p
然后输入密码就可以登录了

你可能感兴趣的:(linux系统,centos,mysql,skip-grant,root,Access,denied)