1. 下载安装包
2. 卸载主机自带的mysql或mariadb
[root@liandoyun ~]# rpm -qa|grepmysql
[root@liandoyun~]# rpm -qa|grepmariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@liandoyun~]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
3. 安装mysql8.0.20
上传安装包至/softbak,解压到/usr/local/
[root@liandoyun ~]# mkdir /softbak
[root@liandoyun~]# cd /softbak/[root@liandoyun softbak]#lsmysql-8.0.20-el7-x86_64.tar.gz
[root@liandoyun softbak]#tar -xzvf mysql-8.0.20-el7-x86_64.tar.gz -C /usr/local/。。。
[root@liandoyun softbak]# cd/usr/local/[root@liandoyun local]#lsbin etc games include lib lib64 libexec mysql-8.0.20-el7-x86_64 sbin share src
[root@liandoyun local]#mv mysql-8.0.20-el7-x86_64/ mysql/
创建mysql用户和组
[root@liandoyun mysql]# groupadd mysql
[root@liandoyun mysql]# useradd -r -g mysql -s /bin/false mysql
创建目录并授权
[root@liandoyun mysql]# mkdir /var/lib/mysql
[root@liandoyun mysql]#mkdir /usr/local/mysql/log
[root@liandoyun mysql]#mkdir /usr/local/mysql/data
[root@liandoyun mysql]#chown -R mysql:mysql /usr/local/mysql
[root@liandoyun mysql]#chown -R mysql:mysql /var/lib/mysql
添加环境变量
[root@liandoyun mysql]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@liandoyun ~]# source ~/.bash_profile
配置参数文件
[root@liandoyun mysql]# vim /etc/my.cnf
[mysql]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
[mysqld]
port= 3306socket=/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=1log-output=FILE
general_log= 0general_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=10log-error=/usr/local/mysql/log/liandodb_error.err
default-authentication-plugin=mysql_native_password
数据库初始化
[root@liandoyun mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
查看初始化日志
[root@liandoyun mysql]# cd /usr/local/mysql/log/[root@liandoyun log]#lsliandodb_error.err liandodb_query.err
[root@liandoyun log]#moreliandodb_error.err2020-05-15T03:09:59.555661Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server inprogress as process1834
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 root@localhost: txu2t6_EGBH:
配置mysql服务
[root@liandoyun 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= 65536LimitNPROC= 65536
[root@liandoyun data]# systemctl daemon-reload
测试服务
[root@liandoyun ~]# systemctl stop mysqld
[root@liandoyun~]# systemctl start mysqld
[root@liandoyun~]#
[root@liandoyun~]# ps -ef | grepmysqld
mysql3986 1 4 11:37 ? 00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
设置开机启动
[root@liandoyun ~]# systemctl enable mysqld
Created symlink from/etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
查看服务状态
[root@liandoyun ~]# systemctl status mysqld?.mysqld.service -MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri2020-05-15 11:37:42CST; 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
May15 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口令
[root@liandoyun ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 8Server version:8.0.20Copyright (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 clearthe current input statement.
mysql>use mysql;
ERROR1820(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.04sec)
mysql>flush privileges;
Query OK,0 rows affected (0.07 sec)
5.设置root远程登录
mysql>use mysql;
Reading table informationforcompletion 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.00sec)
mysql> create USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK,0 rows affected (0.03sec)
mysql> grant all privileges on *.* to 'root'@'%'with grant option;
Query OK,0 rows affected (0.06sec)
mysql>flush privileges;
Query OK,0 rows affected (0.01 sec)
测试远程登陆:
[root@liandoyun ~]# mysql -h 10.0.3.116 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 10Server 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 clearthe current input statement.
mysql>