Centos7安装MySQL8.0版本

使用Yum安装

下载MySQL到本地仓库

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

安装MySQL

yum install mysql-community-server

查看初始化密码

grep 'temporary password' /var/log/mysqld.log

# -defU6-Kkpd/ 就是初始化密码
2019-11-13T08:51:09.863780Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -defU6-Kkpd/

修改配置

修改密码策略

mysql8.0采用的是caching-sha2-password加密策略,有许多客户端目前还不支持,所以需要修改为mysql_native_password,在默认配置文件中,去点面前的注释即可。

vim /etc/my.cnf

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# 修改这里 去点前面注释
default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

配置默认编码

在上面的配置文件中加入如下配置即可:

character_set_server=utf8
init_connect='SET NAMES utf8'

查看编码

mysql> show variables like '%character%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8                           |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8                           |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)

修改密码并开启远程访问

启动服务

service mysqld start

链接mysql

# 提示输入密码,就输入上面筛选出来的密码即可 -defU6-Kkpd/
mysql -uroot -p

修改密码

注意:密码需要数字、字母、字符混合而成,长度最少8位

ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';

开启远程访问

use mysql;
update user set host = '%' where user = 'root';

# 刷新一下权限,不然上面修改是无效的
flush privileges;

测试远程访问

使用Navicat进行远程访问

使用Navicat进行远程访问

开机启动

systemctl enable mysqld
systemctl daemon-reload

查看版本

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18    |
+-----------+
1 row in set (0.00 sec)

命令差异

查看事务隔离级别

# 8.0以前
select @@tx_isolation;
# 8.0之后
select @@transaction_isolation;

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×