卸载
- 卸载之前请确保数据都备份好了阿!
查看是否安装mysql
rpm -qa | grep -i mysql
挨个卸载: rpm -e –nodeps 包名
rpm -e –nodeps mysql-community-libs-8.0.16-2.el7.x86_64
查找之前老版本mysql的目录、并且删除老版本mysql的文件和库
find / -name mysql
挨个删除
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
...
- 注意:卸载后/etc/my.cnf不会删除,需要进行手工删除
rm -rf /etc/my.cnf
检查一遍
rpm -qa | grep -i mysql
find / -name mysql
安装(8.0)
添加MySQL Yum存储库
进入Yum Repository下载页面选择我们需要的版本,点击Download
进入下载页面。
一般选这个
进入下载页面可以拿到下载地址
下载到机器上
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安装存储库
yum localinstall mysql80-community-release-el7-3.noarch.rpm
安装mysql
通过以下命令安装mysql
yum install mysql-community-server
启动MySQL服务器
使用以下命令启动MySQL服务器:
service mysqld start
使用以下命令检查MySQL服务器的状态:
service mysqld status
修改mysql配置文件
vim /etc/my.cnf
给出一个简单的作参考
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html#
[mysqld]
#
# 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
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 设置协议认证方式(重点啊)
default_authentication_plugin=mysql_native_password
# 默认时区
default-time_zone = '+8:00'
# 去掉group限制
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
# 密码验证强度
# 默认为:MEDIUM
# 要求至少包含1个数字字符,1个小写字符,1个大写字符和1个特殊(非字母数字)字符
# 非测试环境请勿添加此项
validate_password.policy=LOW
# 密码验证长度,默认:8
# 非测试环境请勿添加此项
validate_password.length=6
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
重启mysql
systemctl restart mysqld
修改密码
查看默认密码
grep 'temporary password' /var/log/mysqld.log
如果有多行,以最下面一条为准。
登录mysql
mysql -uroot -p
然后输入上面看到的临时密码,小技巧可以使用在中文输入法下输入,密码会在输入法的框框中看得到
需要远程登录
# 切换数据库
use mysql;
# 查看用户信息
select host, user from user;
# 修改root用户访问限制
update user set host='%' where user='root';
# 刷新权限
FLUSH PRIVILEGES;
# 查看用户信息
select host, user from user;
- 注意: 默认情况下root用户对应的host是localhost,图中是因为我已经修改过了。
修改密码
ALTER USER 'root'@'%' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;
不需要远程登录
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;