1.下载
mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
2.解压
tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.15-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local
cd /usr/local/mysql
mkdir data
3.编辑 my.cnf
vi /etc/my.cnf
文件内容为:
[client] port=3306 socket=/tmp/mysql/mysql.sock [mysqld] port=3306 user=mysql socket=/tmp/mysql/mysql.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/data log-error=error.log transaction_isolation = READ-COMMITTED character-set-server = utf8mb4 collation-server = utf8mb4_general_ci lower_case_table_names = 1 #skip-grant-tables
4.创建用户
groupadd mysql
useradd -g mysql mysql
5.更改目录权限
chown -R mysql:mysql /tmp/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /tmp/mysql /usr/local/mysql
6. 初始化
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
7.初始化密码
初始化时并没有出现 初始密码,因此需要修改密码。
注释 skip-grant-tables,可以使用无密码登录
启动 mysql
./support-files/mysql.server start
1.清空密码
use mysql;
update user set authentication_string='' where user='root';
2.无密码登录
mysql -u root -p
输入密码是直接回车。
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
这样就修改好密码了。
自此 mysql 就安装好了。
8 设置自动启动
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
cd /etc/init.d
chkconfig --add mysql
chkconfig --level 345 mysql on
mysql restart
9. 远程连接
1.在 my.cnf 的mysqld 下增加
default_authentication_plugin=mysql_native_password
2.进入mysql命令行
use mysql
update user set host ='%' where user='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
使用客户端工具进行连接。