MySQL安装教程
1、安装包准备
下载地址:https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.33-el7-x86_64.tar.gz
2、环境配置
2.1 my.cnf配置
# vim /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/data01/MySQLData
character_set_server=utf8
max_allowed_packet=500M
collation_server=utf8_general_ci
log-bin=mysql-bin
server-id=1
binlog_format=ROW
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
2.2 MySQL初始化
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.33-el7-x86_64.tar.gz
tar -zxvf mysql-5.7.33-el7-x86_64.tar.gz
groupadd mysql
useradd -g mysql mysql
mv mysql-5.7.33-el7-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
mkdir /data01/MySQLData
chown -R mysql:mysql /data01/MySQLData
# 修改Mysql配置文件
[root@VM-0-17-centos mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data01/MySQLData
2021-09-19T11:14:10.718912Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-19T11:14:11.243855Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-19T11:14:11.379213Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-19T11:14:11.460089Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b73bf74e-193a-11ec-a87c-525400155138.
2021-09-19T11:14:11.463636Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-19T11:14:12.224305Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-19T11:14:12.680671Z 1 [Note] A temporary password is generated for root@localhost: ea+O_hb:86g!
2.3 MySQL设置自启动
[root@VM-0-17-centos mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@VM-0-17-centos mysql]# chkconfig --add mysql
[root@VM-0-17-centos mysql]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@VM-0-17-centos mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@VM-0-17-centos mysql]# source /etc/profile
[root@VM-0-17-centos mysql]# systemctl start mysql
2.4 修改MySQL默认密码
[root@VM-0-17-centos mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33-log
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2.5 开启MySQL远程访问
mysql -uroot -p
# 输入密码
mysql> grant all privileges on *.* to root@'%' identified by "abc123";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
3、报错解决
3.1 缺少libnuma.so.1依赖
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
yum -y install numactl
3.2 default-character-set=utf8 配置错误
[root@VM-0-17-centos mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data01/MySQLData
2021-09-19T11:10:25.173031Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-19T11:10:25.495453Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-19T11:10:25.567349Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-19T11:10:25.634077Z 0 [ERROR] unknown variable 'default-character-set=utf8'
2021-09-19T11:10:25.634100Z 0 [ERROR] Aborting
# 修改mysql.ini即可解决