镜像下载、域名解析、时间同步请点击 阿里云开源镜像站
cd /usr/local
mkdir mysql
cd mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
tar -xvJf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql8.0
cd mysql8.0
mkdir data
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql8.0
Tip:绝对路径:cd /usr/local/mysql/mysql8.0/bin
cd bin
./mysqld —user=mysql —basedir=/usr/local/mysql/mysql8.0 —datadir=/usr/local/mysql/mysql8.0/data/ —initialize
cd /usr/local/mysql/mysql8.0
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
sudo vim my.cnf
```Example MySQL config file for small systems.
This is for a system with little memory (<= 64M) where MySQL is only used
from time to time and it’s important that the mysqld daemon
doesn’t use much resources.
MySQL programs look for option files in a set of
locations which depend on the deployment platform.
You can copy this option file to one of those
locations. For information about these locations, see:
http://dev.mysql.com/doc/mysql/en/option-files.html
In this file, you can use all long options that a program supports.
If you want to know which options a program supports, run the program
with the “—help” option.
[client]
default-character-set=utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir=/usr/local/mysql/mysql8.0
datadir=/usr/local/mysql/mysql8.0/data
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
```
*设置my.cnf权限
sudo chmod 664 /etc/my.cnf
service mysql start
如果出现下面报错
解决
将/var/lock/subsys/下mysql文件删除
service mysql status
ln -s /usr/local/mysql/mysql8.0/bin/mysql /usr/bin
mysql mysql -uroot -p
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
flush privileges;
update user set host=’%’ where user=’root’;
flush privileges;
如果是买的云服务器,例如:阿里云服务器的,请到设置mysql(3306)安全策略
到此就已经完成了在Linux中mysql8.0的所有安装。希望对大家有所帮助。
本文转自:https://blog.csdn.net/qq_45554167/article/details/121907007
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号