apt install libncurses5
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
# 将二进制包放进该目录
tar xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
ln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql #初始化mysql会显示root临时密码
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server
vim /usr/lib/systemd/system/mysql.service
vim /etc/my.cnf
chmod -R 777 /var/log
systemctl enable mysql
systemctl start mysql
vim /etc/profile # >>export PATH=/usr/local/mysql/bin:$PATH
[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 = 5000
[mysqld]
port=3306
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
character-set-server=utf8mb4
socket=/tmp/mysql.sock
log-error=/var/log/mysql-error.log
log-bin=mysql-bin
[mysql]
default-character-set=utf8
socket=/tmp/mysql.sock
[client]
port=3306
default-character-set=utf8
socket=/tmp/mysql.sock
修改root密码:mysqladmin -uroot -p
APT安装MySQL后获取临时账户密码:sudo cat /etc/mysql/debian.cnf
YUM安装后MySQL获取root临时密码:sudo grep 'temporary password' /var/log/mysqld.log
mysql> use mysql;
mysql> update mysql.user set authentication_string='',plugin='mysql_native_password' where user='root';
mysql> flush privileges;
mysql> SHOW VARIABLES LIKE 'validate_password%';
mysql(5.7)> set global validate_password_policy=0;
mysql(5.7)> set global validate_password_length=1;
mysql(8.0)> set global validate_password.policy=0;
mysql(8.0)> set global validate_password.length=1;