mysql 安装mysql
目录
mysql 安装mysql
mysql docker安装
mysql数据库想忽略大小写,如果原先已经有数据了,是无法直接实现的。需要先把数据导出,然后把数据删除改成忽略大小写,再把数据导入,很繁琐,直接创建一个临时的mysql8
安装命令
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -itd mysql --lower_case_table_names=1
//MYSQL_ROOT_PASSWORD 数据库密码
//--lower_case_table_names=1 忽略大小写
验证
mysql -uroot -p123456 -h127.0.0.1
show global variables like '%lower_case%';
mysql docker-compose安装
配置文件
[mysqld]
init-connect="SET collation_connection=utf8mb4_0900_ai_ci"
init_connect="SET NAMES utf8mb4"
skip-character-set-client-handshake
host_cache_size=0
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d
docker-compose.yml
version: "3"
services:
mysql:
image: mysql:8.0
restart: always
container_name: mysql8
volumes:
- /dpss/services/dpss_base/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
- /dpss/data/dpss_base_data/mysql:/var/lib/mysql
- /dpss/logs/dpss_base_logs/mysql:/var/log/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: '123456'
mysql rpm安装
安装包下载
官网: https://dev.mysql.com/downloads/mysql/
下载完成后你应该拥有下面四个包文件
安装mysql
//安装
for i in `ls *.rpm`;do rpm -ivh $i --force --nodeps;done
// 实际上,你只需要安装4个就可以
mysql-community-common-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
//启动
systemctl start mysqld
//获取初始密码
cat /var/log/mysqld.log| grep password
//登陆mysql
mysql -uroot -p
//修改密码
ALTER USER USER() IDENTIFIED BY '123456Admin@123';
//授权
grant all privileges on *.* to 'root'@'%' identified by '123456Admin@123' with grant option;
//刷线权限
flush privileges;
//修改密码策略,把root密码改成更简单的密码
set global validate_password_policy=0;
set global validate_password_length=1;
flush privileges;
//修改root的密码为root
alter user 'root'@'localhost' identified by 'root';
//授权
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
//mysql安装好后,navicat连接不上报错
use mysql;
alter user 'root'@'%' identified with mysql_native_password by 'yourpassword';
flush privileges;