安装 mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
下载安装包mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar。
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
解压安装包
tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
[root@mysql1 mysql8]# ll
mysql-community-client-8.0.23-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.23-1.el7.x86_64.rpm
mysql-community-common-8.0.23-1.el7.x86_64.rpm
mysql-community-devel-8.0.23-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.23-1.el7.x86_64.rpm
mysql-community-libs-8.0.23-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.23-1.el7.x86_64.rpm
mysql-community-server-8.0.23-1.el7.x86_64.rpm
mysql-community-test-8.0.23-1.el7.x86_64.rpm
mysql8.0文档中的安装说明
In most cases, you need to install the mysql-community-server, mysql-community-client,
mysql-community-libs, mysql-community-common, and mysql-community-libs-compat
packages to get a functional, standard MySQL installation. To perform such a standard, basic
installation, go to the folder that contains all those packages (and, preferably, no other RPM packages
with similar names), and issue the following command:
shell>sudo yum install mysql-community-{server,client,common,libs}-*
执行安装 命令
[root@mysql1 mysql8]# yum install mysql-community-{server,client,common,libs}-*
[root@mysql1 mysql8]# 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@mysqlstu1 ~]# tail -f /var/log/mysqld.log
rpm安装不能在my.cnf文件中指定basedir,以下是更改后的my.cnf。
[mysql]
port = 3306
socket = /tmp/mysql.sock
#default-character-set = utf8
prompt = [\\u@\\d]\\R:\\m:\\s>
[client]
#default-character-set = utf8
socket = /tmp/mysql.sock
[mysqld]
default-authentication-plugin=mysql_native_password
user=mysql
#basedir=/usr/local/mysql
datadir=/opt/mydata/data
log-error=/var/log/mysqld.log
socket=/tmp/mysql.sock
#character-set-server= utf8
slow_query_log_file = /opt/mydata/logs/slow.log
log_bin=/opt/mydata/logs/mysql_log_bin
server_id=97
slow_query_log=1
long_query_time=5
log_queries_not_using_indexes=1
innodb_undo_directory=/opt/mydata/undo
innodb_log_files_in_group=3
log_timestamps=SYSTEM
pid-file=/var/run/mysqld/mysqld.pid
#gtid_mode=on
#enforce_gtid_consistency=on
#rpl_semi_sync_master_enabled=on
#rpl_semi_sync_master_wait_for_slave_count=1
#master_info_repository = TABLE
#relay_log_info_repository = TABLE
#binlog_checksum = NONE
再次启动成功
[root@mysql1 mysql8]# systemctl start mysqld
[root@mysql1 mysql8]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-12-23 15:45:23 CST; 27min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2535 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2607 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─2607 /usr/sbin/mysqld
Dec 23 15:45:17 mysqlstu1 systemd[1]: Starting MySQL Server...
Dec 23 15:45:23 mysqlstu1 systemd[1]: Started MySQL Server.
找到root初始密码
[root@mysql1 mydata]# grep 'temporary password' /var/log/mysqld.log
2020-12-23T07:45:19.940049Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 2,h942i#gtuR
[root@mysql1 mysql8]# mysql -uroot -A -p2,h942i#gtuR
[root@(none)]16:13:58>show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
登录后必须要先更新密码
[root@(none)]16:16:32>ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abcd!@34';
Query OK, 0 rows affected (0.00 sec)
密码策略改简单点
[root@sys]16:19:56>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 |
+--------------------------------------+--------+
[root@sys]16:26:24>set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
更改root用户远程登录
[root@sys]16:32:47>update mysql.user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
[root@sys]16:33:26>select User,authentication_string,Host from mysql.user;
+------------------+------------------------------------------------------------------------+-----------+
| User | authentication_string | Host |
+------------------+------------------------------------------------------------------------+-----------+
| root | *281E87151EDAF9135605BA99E36B54FBB222A2C7 | % |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
+------------------+------------------------------------------------------------------------+-----------+
4 rows in set (0.00 sec)
[root@sys]16:33:29>set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
[root@sys]16:36:39>flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@sys]16:37:05>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'abcd' ;
Query OK, 0 rows affected (0.00 sec)
这样就可以远程连接到mysql数据库了。密码策略更改只是临时有效,需要在my.cnf中添加才永久生效。
rpm安装将mysql安装到了/usr/share目录中
[root@mysqlstu1 bin]# ls /usr/share/mysql-8.0
bulgarian dictionary.txt french innodb_memcached_config.sql korean norwegian romanian spanish
charsets dutch german install_rewriter.sql messages_to_clients.txt norwegian-ny russian swedish
czech english greek italian messages_to_error_log.txt polish serbian ukrainian
danish estonian hungarian japanese mysql-log-rotate portuguese slovak uninstall_rewriter.sql
小结一下:
1、rpm安装时不要指定basedir;
2、初始化mysql时如果出现错误,再次执行前要删除datadir中的所有文件;
3、查看mysql错误日志时发现时间与系统时间不一致,相差8个小时,mysql有一个全局变量log_timestamps默认为UTC,
可以通过set global log_timestamps=SYSTEM;临时设置为与系统一致,当系统重启后,配置就失效,需要添加到my.cnf中。