mysql8.0 安装
1.解压
tar -xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
cd /usr/local/mysql/
mv mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
mkdir data
cd /tmp/
mkdir mysql
2.编辑 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
3.创建用户
groupadd mysql
useradd -g mysql mysql
4.更改目录权限
chown -R mysql:mysql /tmp/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /tmp/mysql /usr/local/mysql
5. 初始化
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
如有报错
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
则需要安装libaio包
[root@80_2 mysql]# yum install -y libaio
6.初始化密码
初始化时并没有出现 初始密码,因此需要修改密码。
注释 skip-grant-tables,可以使用无密码登录
7.启动 mysql
[root@80_2 mysql]# ./support-files/mysql.server start
8.登录mysql
/usr/local/mysql/bin/mysql -u root -p 直接回车
9.清空密码
use mysql;
update user set authentication_string='' where user='root';
10.去掉无密码登录
vim /etc/my.cnf
./support-files/mysql.server restart
/usr/local/mysql/bin/mysql -u root -p直接回车
11.修改密码
mysql>alter user root@'localhost' identified by '123456';这样就修改好密码了。
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.27 |
+-----------+
12.设置自动启动
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
13.重启mysql
service mysql restart
service mysql stop
(1)创建可远程连接用户
CREATE USER 'root'@'%' IDENTIFIED BY '111111';※创建用户
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '111111'; ※修改用户密码
FLUSH PRIVILEGES; ※刷新权限
如果用Navicat连接的回报不支持caching_sha2_password验证方式的错误。
将远程访问用户的验证方式改为: msyql_native_password
(2)查看用户
select host,user,plugin,authentication_string from mysql.user;
备注:host为 % 表示不限制ip localhost表示本机使用 plugin非mysql_native_password 则需要修改密码
(3)修改用户密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newpassword'; #更新一下用户的密码 root用户密码为newpassword