centos7.7 安装 mysql8.0.20
1. 下载安装包
2. 卸载主机自带的mysql或mariadb
[ ~]# rpm -qa|grep mysql [ ~]# rpm -qa|grep mariadb mariadb-libs-5.5.64-1.el7.x86_64 [ ~]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
3. 安装mysql8.0.20
上传安装包至/softbak,解压到/usr/local/
[ ~]# mkdir /softbak [ ~]# cd /softbak/ [ softbak]# ls mysql-8.0.20-el7-x86_64.tar.gz [ softbak]# tar -xzvf mysql-8.0.20-el7-x86_64.tar.gz -C /usr/local/ 。。。 [ softbak]# cd /usr/local/ [ local]# ls bin etc games include lib lib64 libexec mysql-8.0.20-el7-x86_64 sbin share src [ local]# mv mysql-8.0.20-el7-x86_64/ mysql/
创建mysql用户和组
[ mysql]# groupadd mysql
[ mysql]# useradd -r -g mysql -s /bin/false mysql
[ mysql]# chown -R mysql:mysql /usr/local/mysql
[ mysql]# chown -R mysql:mysql /var/lib/mysql
创建目录并授权
[ mysql]# mkdir /var/lib/mysql [ mysql]# mkdir /usr/local/mysql/log [ mysql]# mkdir /usr/local/mysql/data [ mysql]# chown -R mysql:mysql /usr/local/mysql [ mysql]# chown -R mysql:mysql /var/lib/mysql
添加环境变量
[ mysql]# vim ~/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/mysql/bin[ ~]# source ~/.bash_profile
配置参数文件
[ mysql]# vim /etc/my.cnf [mysql] default-character-set=utf8mb4 socket=/var/lib/mysql/mysql.sock [mysqld] port = 3306 socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql character-set-server=utf8mb4 default-storage-engine=INNODB innodb_buffer_pool_size = 200M max_allowed_packet=16M explicit_defaults_for_timestamp=1 log-output=FILE general_log = 0 general_log_file=/usr/local/mysql/log/liandodb_general.err slow_query_log = ON slow_query_log_file=/usr/local/mysql/log/liandodb_query.err long_query_time=10 log-error=/usr/local/mysql/log/liandodb_error.err default-authentication-plugin=mysql_native_password
数据库初始化
[ mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
查看初始化日志
[ mysql]# cd /usr/local/mysql/log/ [ log]# ls liandodb_error.err liandodb_query.err [ log]# more liandodb_error.err 2020-05-15T03:09:59.555661Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 1834 2020-05-15T03:09:59.623225Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-05-15T03:10:03.164817Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-05-15T03:10:08.144133Z 6 [Note] [MY-010454] [Server] A temporary password is generated for : txu2t6_EGBH:
配置mysql服务
[ data]# vim /usr/lib/systemd/system/mysqld.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 65536 LimitNPROC = 65536[ data]# systemctl daemon-reload
测试服务
[ ~]# systemctl stop mysqld [ ~]# systemctl start mysqld [ ~]# [ ~]# ps -ef | grep mysqld mysql 3986 1 4 11:37 ? 00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
设置开机启动
[ ~]# systemctl enable mysqld Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
查看服务状态
[ ~]# systemctl status mysqld ?.mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-05-15 11:37:42 CST; 2min 1s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 3986 (mysqld) CGroup: /system.slice/mysqld.service ?..3986 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf May 15 11:37:42 liandoyun systemd[1]: Started MySQL Server.
手动启停命令:
启动:nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & 停止: mysqladmin -uroot -p shutdown -S /var/lib/mysql/mysql.sock
4.修改root口令
[ ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 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> use mysql; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘root‘; Query OK, 0 rows affected (0.04 sec) mysql> flush privileges; Query OK, 0 rows affected (0.07 sec)
5.设置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> select host,user from user where user=‘root‘; +-----------+------+ | host | user | +-----------+------+ | localhost | root | +-----------+------+ 1 row in set (0.00 sec) mysql> create USER ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘root‘; Query OK, 0 rows affected (0.03 sec) mysql> grant all privileges on *.* to ‘root‘@‘%‘ with grant option; Query OK, 0 rows affected (0.06 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
测试远程登陆:
[ ~]# mysql -h 10.0.3.116 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 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>