下载地址:
https://downloads.mysql.com/archives/community/
1、上传至安装目录
cd /usr/local/mysql
2、解压
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
3、重命名
mv mysql-5.7.32-linux-glibc2.12-x86_64 mysql
4、创建data文件:存放数据表及其它文件
cd mysql
mkdir data
5、创建用户组
groupadd mysql
6、添加mysql用户
useradd -g mysql mysql
7、授权用户
chown -R mysql.mysql /usr/local/mysql
8、拷贝mysql.server至/etc/init.d/mysql 添加mysqld服务到系统
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
9、新建 /etc/my.cnf
vim /etc/my.cnf
[client]
default-character-set=utf8mb4
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# The MySQL server
[mysqld]
# 自己配置的mysql的文件夹 和 mysql data目录
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 64M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
bind-address = 0.0.0.0
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
default-character-set = utf8mb4
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
10、初始化基础信息,最后一行有密码
cd bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql
./mysqld_safe --user=mysql
11、添加mysql命令到服务
ln -s /usr/local/mysql/bin/mysql /usr/bin
12、连接mysql
./mysql -uroot -p
13、修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'liujianming';
#注意:每一句后面都要加“;”
flush privileges;
use mysql;
update user set host='%' where user='root';
flush privileges;
14、防火墙
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
15、开放(云)服务器端口
16、启动命令
service mysql start #启动MySQL
service mysql stop #停止MySQL
service mysql restart #重启MySQL
service mysql status #查看MySQL状态
感谢观看,如帮到您,不吝点赞。