docker 安装 mysql 8

2020-09-02  本文已影响0人  吉他手_c156

拉取 msyql 镜像

docker pull mysql:8.0.18

创建 mysql 8 守护式容器

docker run -di --name=mysql8 -p 3306:3306 -v /usr/local/tmp:/etc/mysql/tmp --privileged=true -e MYSQL_ROOT_PASSWORD=xxx mysql:8.0.18

进入容器

docker exec -it mysql8[容器id] /bin/bash

进入数据库

mysql> grant all on *.* to 'admin'@'%' identified by 'admin123';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'admin123'' at line 1
mysql> create user  'admin'@'%' identified by 'admin123';
Query OK, 0 rows affected (0.06 sec)

mysql> grant all on *.* to 'admin'@'%' ;
Query OK, 0 rows affected (0.04 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MySQL 解决source 命令导入数据库 乱码

配置文件解决 myql 导入中文乱码
deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
  1. apt-update 激活后,执行安装 vim 命令
    • apt-get install vim

等待安装完成后,就可以使用 vim 命令了

vim /etc/mysql/my.cnf


image.png
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/
[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

保存退出

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/
上一篇 下一篇

猜你喜欢

热点阅读