标签:下载 ESS pass 脚本 runtime 使用 连接 general mysql
在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。
下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
yum -y remove mysql57-community-release-el7-10.noarch
systemctl start mysqld.service
systemctl status mysqld.service
查看MySQL默认的root密码
grep "password" /var/log/mysqld.log
修改root密码
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED BY 'new password';
flush privileges;
修改配置文件
// do something...
下载并安装MySQL官方的 Yum Repository
wget -i -c https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum -y install mysql80-community-release-el7-1.noarch.rpm
yum -y install mysql-community-server
yum -y remove mysql80-community-release-el7-1.noarch
systemctl start mysqld.service
systemctl status mysqld.service
查看MySQL默认的root密码
grep "password" /var/log/mysqld.log
修改root密码
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED BY 'new password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'new password';
flush privileges;
修改配置文件
// do something...
version: '3'
services:
# ref:https://hub.docker.com/_/mysql
# ref:https://docs.docker.com/samples/library/mysql/#-via-docker-stack-deploy-or-docker-compose
mysql:
image: mysql:5.7.22
container_name: mysql
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
# data 用来存放了数据库表文件,init存放初始化的脚本
volumes:
- ./mysql/data/:/var/lib/mysql/
- ./mysql/conf/my.cnf:/etc/my.cnf
- ./mysql/init:/docker-entrypoint-initdb.d/
restart: always
ports:
- "3306:3306"
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: root
version: '3'
services:
# ref:https://hub.docker.com/_/mysql
# ref:https://docs.docker.com/samples/library/mysql/#-via-docker-stack-deploy-or-docker-compose
mysql:
image: mysql:8.0
container_name: mysql
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
# data 用来存放了数据库表文件,init存放初始化的脚本
volumes:
- ./mysql/data/:/var/lib/mysql/
- ./mysql/conf/my.cnf:/etc/my.cnf
- ./mysql/init:/docker-entrypoint-initdb.d/
restart: always
ports:
- "3306:3306"
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: root123
MYSQL_USER: dev
MYSQL_PASSWORD: dev123
#写好docker-compose.yml文件后使用命令启动容器
docker-compose up -d
docker-compose ps
com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的;MySQL8需要使用com.mysql.cj.jdbc.Driver驱动。
mysql8.0驱动:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
<scope>runtime</scope>
</dependency>
jdbc:mysql://localhost:3306/database?useUnicode=true&serverTimezone=GMT%2B8&useSSL=false&autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
该异常原因是:在mysql8之前的版本使用的密码加密规则是mysql_native_password,但是在mysql8则是caching_sha2_password。
解决方案
docker exec -ti mysql /bin/bash
mysql -u root -p root123;
ALTER USER 'root'@'%' IDENTIFIED BY 'your password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your password';
FLUSH PRIVILEGES;
标签:下载 ESS pass 脚本 runtime 使用 连接 general mysql
原文地址:https://www.cnblogs.com/kancy/p/install_mysql.html