一、单机安装
1.1 二进制包安装
1.1.1 下载mysql
- https://dev.mysql.com/downloads/mysql/
1.1.2 解压
xz -d mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar
1.1.3 配置用户和用户组
sudo groupadd mysql
useradd -r mysql
chown mysql:mysql -R mysql-8.0.18-linux-glibc2.12-x86_64
1.1.4 初始化
```shell cd mysql-8.0.18-linux-glibc2.12-x86_64/ sudo ./bin/mysqld —user=mysql —basedir=$PWD —datadir=$PWD/data —initialize
#命令行中打印的账号root的随机密码: root@localhost: FUh+W/TVe92p
<a name="F9dwJ"></a>
##### 1.1.5 启动
```shell
sudo ./support-files/mysql.server start
#输出
Starting MySQL
[.ok
1.1.6 配置
#加入系统进程
sudo cp support-files/mysql.server /etc/init.d/mysqld
#重启
service mysqld restart
#在/usr/bin下建立指向mysql的软连接(方便使用mysql 客户端)
#$PWD : /home/hdj/software/mysql
sudo ln -s $PWD/bin/mysql /usr/bin
#登录mysql (输入随机密码)
mysql -uroot -p
#修改密码
#ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
alter user 'root'@'localhost' identified by '123456';
#开机自启动
sudo systemctl enable mysqld
1.1.7 卸载
#停止mysql 服务
service mysqld stop
#关闭自动启动
sudo systemctl disenable mysqld
# 删除mysql 文件
sudo rm -rf /usr/bin/mysql /etc/mysql /etc/init.d/mysqld
#删除用户及用户组
userdel mysql
#查看
ps -ef | grep mysql
1.2 docker 安装
docker pull mysql:8.0.21
docker run --name blog-mysql-serve \
-e MYSQL_ROOT_PASSWORD=123456 \
-e TZ=Asia/Shanghai -d -i -p 4406:3306 \
-v $PWD/data:/var/lib/mysql \
-v $PWD/conf/my.conf:/etc/mysql/my.conf \
--restart=always mysql:8.0.21
//忽略表名大小写(mysql 命令)
--lower_case_table_names=1 忽略表名大小写(linux)
//数据挂载,配置挂载
//(/home/hdj/docker/mysql/conf:目录)
-v /home/hdj/docker/mysql/conf:/etc/mysql/conf.d
//数据挂载
-v /my/own/datadir:/var/lib/mysql
//root密码
-e MYSQL_ROOT_PASSWORD=1234
//创建用户
-e MYSQL_USER="dev"
//新建用户密码
-e MYSQL_PASSWORD="dev1234"
//时区
-e TZ=Asia/Shanghai
//开机启动
--restart=always
//提升容器权限
--privileged=true
1.3 mysql 配置文件
[mysqld]
secure-file-priv = NULL
#忽略表大小写
lower_case_table_names = 1
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
1.4 mysql 修改密码验证器
select host,user,plugin,authentication_string from mysql.user;
#修改用户访问权限
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;