记录一下Linux系统上的各种MySQL安装姿势~
一 Centos下安装MySQL
1. yum源安装
环境:centos7? +?MySQL8.0
(1)安装和启动
curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm
yum install centos7.mysql.rpm -y
yum install mysql-community-server -y
systemctl start mysqld
systemctl enable mysqld
# 查看mysql的状态
systemctl status mysqld
(2)修改配置
# 查看初始密码
cat /var/log/mysqld.log | grep "password"
# 安全初始化
mysql_secure_installation
# 省略设置密码的步骤。。。
# 用root账号登录
mysql -uroot -p
- 数据库常用操作、新增用户,分配权限,root用户远程登录
# 展示现有的数据库
show databases;
# 创建用户 drizzle 密码为:Drizzle123
create user drizzle@'%' identified by 'Drizzle123';
# 查看当前有哪些用户
select user,authentication_string,host from mysql.user;
# 创建一个数据库 demodb
create database demodb charset=utf8;
# 给用户drizzle分配数据库demodb的所有权限
grant all on demodb .* to drizzle;
# 刷新权限
flush privileges;
# 显示drizzle用户有哪些权限
show grants for drizzle;
# 允许root用户远程登录
update user set host='%' where user='root';
# 退出数据库命令行
exit
# 将root用户的密码改为:Drizzle123 (并设置为永不过期)
ALTER USER 'root'@'%' IDENTIFIED BY 'Drizzle123' PASSWORD EXPIRE NEVER;
# 将drizzle用户的密码改为:Drizzle123 (并指定加密规则为 mysql_native_password)
ALTER USER 'drizzle'@'%' IDENTIFIED WITH mysql_native_password BY 'Drizzle123';
# 刷新权限
flush privileges;
# 查看一下防火墙状态
systemctl status firewalld
# 开放3306端口的远程访问权限
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 刷新防火墙规则
firewall-cmd --reload
# 重启MySQL
systemctl restart mysqld
(3)安装过程中遇到的问题
Navicat连接过程中,出现 2059 - authentication plugin... 错误
原因是Navicat不支持MySQL新版本用户登录账户加密方式,所以通过命令行登录mysql后修改root账户的加密方式为【mysql_native_password】即可,如下:
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Drizzle123.';
2. 压缩包安装
二 Ubuntu下安装MySQL
三 Docker安装MySQL
其余待补充......
|