测试环境:阿里云
首先下载
yum -y install bash-compl*
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
systemctl start mysqld
ss -ntulp | grep 3306
vim /etc/my.cnf
skip-grant-tables
update mysql.user set authentication_string = password('123qqq...A') where user='root';
create database user;
use user;
create table rr(id int auto_increment,name char(5),age tinyint,primary key(id));
insert into rr(name,age) values('xixi',20);
insert into rr(name,age) values('haha',21);
insert into rr(name,age) values('lisi',22);
停mysql5.7
1.修改环境
vm /etc/my.cnf /etc/my.cnf.bak
vim /etc/profile
#注释下面信息
#export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
[root@i ~]# systemctl stop mysqld
[root@i ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@i ~]# vim /etc/profile
[root@i ~]# mkdir /data/app
[root@i ~]# cd /data/app/
[root@i app]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
[root@i app]# tar xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
[root@i app]# mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql80
[root@i app]# mkdir -p /data/3326/data
[root@i app]# /data/app/mysql80/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql80 --datadir=/data/3326/data
2022-09-08T02:57:01.158375Z 0 [System] [MY-013169] [Server] /data/app/mysql80/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 4674
2022-09-08T02:57:06.094027Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@i app]# chown -R mysql:mysql /data/*
[root@i app]# vim /data/3326/my.cnf
[mysqld]
user=mysql
basedir=/data/app/mysql80
datadir=/data/3326/data
socket=/tmp/mysql.sock
port=3326
erver_id=26
[root@i app]# vim /etc/systemd/system/mysql3326.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=/data/app/mysql80/bin/mysqld --defaults-file=/data/3326/my.cnf
LimitNOFILE = 5000
mv /etc/my.cnf.bak /etc/my.cnf
vim /etc/profile
export PATH=/usr/local/apache/bin:/usr/local/php/bin:/data/app/mysql80/bin:$PATH
source /etc/profile
修改MySQL的配置文件(指向新的数据库目录)
vim /etc/my.cnf
basedir = /data/app/mysql80
注释下列三行信息(版本不兼容问题)
#query_cache_type = 1
#query_cache_size = 8M
#query_cache_limit = 2M
重启数据库服务:systemctl start mysqld
登入数据库服务:mysql -uroot -p
查看信息:
MySQL [(none)]> select version();
+-----------+
| version() |
+-----------+
| 8.0.18 |
+-----------+
1 row in set (0.00 sec)
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| user |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> select * from user.rr;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | xixi | 20 |
| 2 | haha | 21 |
| 3 | lisi | 22 |
+----+------+------+
3 rows in set (0.00 sec)