yum install -y docker.io
yum install -y epel-release
mysql
我這邊是centos7.5,因此修改鏡像配置在/etc/docker/daemon.json
增長sql
{ "registry-mirrors": ["https://id.mirror.aliyuncs.com"] }
其餘系統本身去搜docker
搜索mysql鏡像,或者直接安裝最新版docker search mysql
拉取鏡像docker pull mysql:latest
安裝的是最新的mysql:8.0.19
查看可用鏡像docker images
運行mysql鏡像數據庫
docker run -d --name mysql -p 3306:3306 -v /usr/local/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=你的密碼 docker.io/mysql:8.0.19
關於參數的解釋-d 後臺運行
--name 設置別名
-p 端口映射 冒號前爲本機端口
-v 目錄掛載 冒號前爲本機目錄
-e 環境配置參數 這裏設置的是root密碼
最後其實我不太明白爲什麼個人鏡像運行要加docker.io/,網上搜到的鏡像名都是直接mysql而已json
首先要查看容器全IDdocker inspect mysql(這裏是你的容器別名)
把以前服務器導出的sql腳本複製到docker容器中docker cp /usr/local/scripts/mysql-bak.sql 容器全ID:/usr/local/scripts
導入了以前服務器的腳本後,發現亂碼,一查數據庫編碼show variables like 'character%';
長這逼樣vim
+--------------------------+--------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql-8.0/charsets/ | +--------------------------+--------------------------------+ 8 rows in set (0.01 sec)
什麼年代了,爲何還不默認utf8,不太明白centos
故要設置my.cnf,又發現容器中沒有vim,因此接下來繼續在容器中安裝vim服務器
更新aptapt-get update
發現很慢,又去更新apt的鏡像,地址在/etc/apt/sources.list
更新爲用網易的鏡像session
deb http://mirrors.163.com/debian/ jessie main non-free contrib deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib deb-src http://mirrors.163.com/debian/ jessie main non-free contrib deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
更新後速度飛快,很少逼逼,繼續安裝apt-get update
apt-get install vim
結果報錯ide
Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: vim : Depends: libtinfo5 but it is not going to be installed
幸虧還有小學英語水平,這最後一句說的是沒有libtinfo5的依賴,那我再安裝這個玩意apt-get install libtinfo5
終於尼瑪的完成了
接下來編輯my.cnf,在mysqld下面黏貼幾個玩意
character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci
docker restart mysql
終於正常了,佛了
查看用戶權限
mysql> select host,user,plugin,authentication_string from user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+ | host | user | plugin | authentication_string | +-----------+------------------+-----------------------+------------------------------------------------------------------------+ | % | root | caching_sha2_password | $A$005$f&/uW)ZX LcE%"f3mdndFClPzqRACxH9vTuOk90Gs12jnuKt0k4Ens9IB | | localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | root | caching_sha2_password | $A$005$k{`vW;lca|%)f~lr[T6ot4.MCPhmNFHKzti8SS0TwxMgcubqb2l89hTIlr44 | +-----------+------------------+-----------------------+------------------------------------------------------------------------+
這個鏡像好像默認開啓了root的遠程鏈接權限,可是卻沒法用navicat登工具進行鏈接
mysql8默認的身份驗證插件爲caching_sha2_password
,該插件不能使用舊版本的客戶端來鏈接(也許新的第三方客戶端能夠鏈接該插件),粘貼一份mysql官方的說明
If your MySQL installation must serve pre-8.0 clients and you encounter compatibility issues after upgrading to MySQL 8.0 or higher, the simplest way to address those issues and restore pre-8.0 compatibility is to reconfigure the server to revert to the previous default authentication plugin (
mysql_native_password
). For example, use these lines in the server option file:[mysqld] default_authentication_plugin=mysql_native_passwordThat setting enables pre-8.0 clients to connect to 8.0 servers until such time as the clients and connectors in use at your installation are upgraded to know about
caching_sha2_password
. However, the setting should be viewed as temporary, not as a long term or permanent solution, because it causes new accounts created with the setting in effect to forego the improved authentication security provided bycaching_sha2_password
.
故修改插件爲mysql_native_passwordALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密碼’;
大功告成