CentOS8 安装 MySQL8.0(RPM)

环境:Linux centos8 4.18.0-80.el8.x86_64、Mysql8.0.20-1

Mysql官网下载RPM包

在这里插入图片描述
直接下载链接:
mysql-community-server-8.0.20-1.el8.x86_64
mysql-community-client-8.0.20-1.el8.x86_64.rpm
mysql-community-common-8.0.20-1.el8.x86_64.rpm
mysql-community-libs-8.0.20-1.el8.x86_64.rpm

卸载其他版本

检查是否安装过

[root@localhost work]# rpm -qa | grep -i mysql
[root@localhost work]# 

卸载之前的安装

rpm -e --nodeps 软件名 //强力删除,对相关依赖的文件也进行强力删除

安装MySQL8.0

安装客户端(mysql-client)

rpm -ivh rpm包

  • 安装mysql-community-common-8.0.20
  • 安装mysql-community-libs-8.0.20
  • 安装mysql-community-client-8.0.20(前两个是其依赖)
[root@localhost mysql8.0]# rpm -ivh mysql-community-common-8.0.20-1.el8.x86_64.rpm 
warning: mysql-community-common-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.20-1.e################################# [100%]

[root@localhost mysql8.0]# rpm -ivh mysql-community-libs-8.0.20-1.el8.x86_64.rpm 
warning: mysql-community-libs-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.20-1.el8################################# [100%]

[root@localhost mysql8.0]# rpm -ivh mysql-community-client-8.0.20-1.el8.x86_64.rpm 
warning: mysql-community-client-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.20-1.e################################# [100%]
[root@localhost mysql8.0]# 

安装服务端(mysql-server)

rpm -ivh mysql-community-server-8.0.20-1.el8.x86_64.rpm --force --nodeps // --force --nodeps主要是解决这是由于yum安装了旧版本的GPG keys造成的error错误

[root@localhost mysql8.0]# rpm -ivh mysql-community-server-8.0.20-1.el8.x86_64.rpm 
warning: mysql-community-server-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	net-tools is needed by mysql-community-server-8.0.20-1.el8.x86_64

[root@localhost mysql8.0]# rpm -ivh mysql-community-server-8.0.20-1.el8.x86_64.rpm  --force --nodeps
warning: mysql-community-server-8.0.20-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.20-1.e################################# [100%]
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.
[root@localhost mysql8.0]# 

查看是否安装成功

有以下方式查看:

  • ps -ef | grep mysql
  • cat /etc/group | grep mysql
  • cat /etc/password | grep mysql
  • mysqladmin --version
[root@localhost mysql8.0]# ps -ef | grep mysql
root       2546   1327  0 22:56 pts/0    00:00:00 grep --color=auto mysql
[root@localhost mysql8.0]# cat /etc/group | grep mysql
mysql:x:27:
[root@localhost mysql8.0]# cat /etc/password | grep mysql
cat: /etc/password: No such file or directory
[root@localhost mysql8.0]# mysqladmin --version
mysqladmin  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)
[root@localhost mysql8.0]# 

初始化mysql

mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码

[root@localhost mysql8.0]# mysqld --initialize
[root@localhost mysql8.0]# 

启动mysql服务

systemctl start mysqld

[root@localhost mysql8.0]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@localhost mysql8.0]# 

启动失败,因为/var/lib/mysql目录权限不够

[root@localhost mysql8.0]# ll /var/lib/mysql/
total 164280
-rw-r----- 1 root  root        56 May 22 22:59  auto.cnf
-rw-r----- 1 mysql mysql        0 May 22 23:00  binlog.index
-rw------- 1 root  root      1676 May 22 22:59  ca-key.pem
-rw-r--r-- 1 root  root      1112 May 22 22:59  ca.pem
-rw-r--r-- 1 root  root      1112 May 22 22:59  client-cert.pem
-rw------- 1 root  root      1680 May 22 22:59  client-key.pem
-rw-r----- 1 root  root    196608 May 22 22:59 '#ib_16384_0.dblwr'
-rw-r----- 1 root  root   8585216 May 22 22:59 '#ib_16384_1.dblwr'
-rw-r----- 1 root  root      5497 May 22 22:59  ib_buffer_pool
-rw-r----- 1 root  root  12582912 May 22 22:59  ibdata1
-rw-r----- 1 root  root  50331648 May 22 22:59  ib_logfile0
-rw-r----- 1 root  root  50331648 May 22 22:59  ib_logfile1
drwxr-x--- 2 root  root         6 May 22 22:59 '#innodb_temp'
drwxr-x--- 2 root  root       143 May 22 22:59  mysql
-rw-r----- 1 root  root  25165824 May 22 22:59  mysql.ibd
drwxr-x--- 2 root  root      8192 May 22 22:59  performance_schema
-rw------- 1 root  root      1676 May 22 22:59  private_key.pem
-rw-r--r-- 1 root  root       452 May 22 22:59  public_key.pem
-rw-r--r-- 1 root  root      1112 May 22 22:59  server-cert.pem
-rw------- 1 root  root      1676 May 22 22:59  server-key.pem
drwxr-x--- 2 root  root        28 May 22 22:59  sys
-rw-r----- 1 root  root  10485760 May 22 22:59  undo_001
-rw-r----- 1 root  root  10485760 May 22 22:59  undo_002
[root@localhost mysql8.0]# 

/var/lib/mysql目录权限授权

chown -R mysql:mysql /var/lib/mysql/

[root@localhost mysql8.0]# chown -R mysql:mysql /var/lib/mysql/
[root@localhost mysql8.0]# ll /var/lib/mysql/
total 164280
-rw-r----- 1 mysql mysql       56 May 22 22:59  auto.cnf
-rw-r----- 1 mysql mysql        0 May 22 23:00  binlog.index
-rw------- 1 mysql mysql     1676 May 22 22:59  ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 May 22 22:59  ca.pem
-rw-r--r-- 1 mysql mysql     1112 May 22 22:59  client-cert.pem
-rw------- 1 mysql mysql     1680 May 22 22:59  client-key.pem
-rw-r----- 1 mysql mysql   196608 May 22 22:59 '#ib_16384_0.dblwr'
-rw-r----- 1 mysql mysql  8585216 May 22 22:59 '#ib_16384_1.dblwr'
-rw-r----- 1 mysql mysql     5497 May 22 22:59  ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 22 22:59  ibdata1
-rw-r----- 1 mysql mysql 50331648 May 22 22:59  ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 22 22:59  ib_logfile1
drwxr-x--- 2 mysql mysql        6 May 22 22:59 '#innodb_temp'
drwxr-x--- 2 mysql mysql      143 May 22 22:59  mysql
-rw-r----- 1 mysql mysql 25165824 May 22 22:59  mysql.ibd
drwxr-x--- 2 mysql mysql     8192 May 22 22:59  performance_schema
-rw------- 1 mysql mysql     1676 May 22 22:59  private_key.pem
-rw-r--r-- 1 mysql mysql      452 May 22 22:59  public_key.pem
-rw-r--r-- 1 mysql mysql     1112 May 22 22:59  server-cert.pem
-rw------- 1 mysql mysql     1676 May 22 22:59  server-key.pem
drwxr-x--- 2 mysql mysql       28 May 22 22:59  sys
-rw-r----- 1 mysql mysql 10485760 May 22 22:59  undo_001
-rw-r----- 1 mysql mysql 10485760 May 22 22:59  undo_002
[root@localhost mysql8.0]# 

重新启动mysql服务

systemctl start mysqld //启动
ps -ef | grep mysql //查看mysql服务

[root@localhost mysql8.0]# systemctl start mysqld
[root@localhost mysql8.0]# ps -ef | grep mysql
mysql      2680      1  6 23:12 ?        00:00:01 /usr/sbin/mysqld
root       2726   1327  0 23:12 pts/0    00:00:00 grep --color=auto mysql
[root@localhost mysql8.0]# 

查看初始化随机生成的root密码

cat /var/log/mysqld.log | grep password

[root@localhost mysql8.0]# cat /var/log/mysqld.log | grep password
2020-05-22T14:59:39.740017Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: won-V%kYc1al

安全设置

用户root密码可不设置,后面回修改
mysql_secure_installation

[root@localhost mysql8.0]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:    //输入 won-V%kYc1al

The existing password for the user account root has expired. Please set a new password.

New password:                    // 输入新密码 won-V%kYc1al

Re-enter new password:           // 输入新密码 won-V%kYc1al

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No    //是否需要修改root用户密码

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y            // 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y     // 是否删除匿名用户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No    // 是否禁止root远程连接

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y   // 是否删除测试数据库
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y    // 是否重新加载权限表
Success.

All done! 
[root@localhost mysql8.0]# 

使用

mysql登录

mysql -uroot -p

[root@localhost mysql8.0]# mysql -u root -p
Enter password:       //输入 won-V%kYc1al
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.20 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> 

重置密码(Mysql8.0+有变化)

先把root的旧密码置空

use mysql;
update user set authentication_string=’’ where user=‘root’;
备注:Mysql5.7+ password字段 已改成 authentication_string字段
MySQL8.0 忘记 root 密码下如何修改密码

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 authentication_string='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

重置成新密码

alter user ‘root’@‘localhost’ identified by ‘root’;
备注:Mysql8.0修改密码方式已有变化(此处是个坑,需要注意)


mysql> alter user 'root'@'localhost' identified by 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> 

修改密码策略配置

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 错误原因,版本8.0 默认设置密码不能相同于用户名
validate_password.check_user_name | ON // 校验密码不能等同于用户名
validate_password.policy | LOW // 设置低级别策略
validate_password.length | 4 // 设置最低长度为4

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             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)


mysql> set global validate_password.check_user_name=OFF;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%'; 
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | OFF   |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)


mysql> 

重新修改密码

设置完密码策略后重新输入修改命令

mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.01 sec)

如何停止、重启和查看mysql服务

systemctl stop mysqld //停止服务
systemctl restart mysqld //重启服务
systemctl status mysqld //查看服务

mysql的相关安装目录文件

/usr/bin //相关命令

[root@localhost mysql8.0]# ls /usr/bin/my*
/usr/bin/myisamchk          /usr/bin/mysqlbinlog          /usr/bin/mysqlpump
/usr/bin/myisam_ftdump      /usr/bin/mysqlcheck           /usr/bin/mysql_secure_installation
/usr/bin/myisamlog          /usr/bin/mysql_config_editor  /usr/bin/mysqlshow
/usr/bin/myisampack         /usr/bin/mysqld_pre_systemd   /usr/bin/mysqlslap
/usr/bin/my_print_defaults  /usr/bin/mysqldump            /usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysql              /usr/bin/mysqldumpslow        /usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysqladmin         /usr/bin/mysqlimport          /usr/bin/mysql_upgrade
[root@localhost mysql8.0]# 

/usr/share/mysql-8.0/ //配置文件目录

[root@localhost mysql8.0]# ls /usr/share/mysql-8.0/
bulgarian       french                       korean                     romanian
charsets        german                       messages_to_clients.txt    russian
czech           greek                        messages_to_error_log.txt  serbian
danish          hungarian                    mysql-log-rotate           slovak
dictionary.txt  innodb_memcached_config.sql  norwegian                  spanish
dutch           install_rewriter.sql         norwegian-ny               swedish
english         italian                      polish                     ukrainian
estonian        japanese                     portuguese                 uninstall_rewriter.sql
[root@localhost mysql8.0]# 

/var/lib/mysql //数据库文件存放目录

[root@localhost mysql8.0]# ls /var/lib/mysql/
 auto.cnf        client-cert.pem      ibdata1         mysql                private_key.pem   undo_001
 binlog.000001   client-key.pem       ib_logfile0     mysql.ibd            public_key.pem    undo_002
 binlog.index   '#ib_16384_0.dblwr'   ib_logfile1     mysql.sock           server-cert.pem
 ca-key.pem     '#ib_16384_1.dblwr'   ibtmp1          mysql.sock.lock      server-key.pem
 ca.pem          ib_buffer_pool      '#innodb_temp'   performance_schema   sys
[root@localhost mysql8.0]# 

/etc/my.cnf //mysql的启动配置文件

[root@localhost mysql8.0]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost mysql8.0]# 

  • 8
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值