Docker安裝MariaDB-10.2
阿新 • • 發佈:2020-08-03
1 docker search mariadb 搜尋mariadb映象(非必須)
2 docker pull mariadb 下載docker映象
3 docker images 檢視本地已有的所有映象
4 mkdir -p /data/mariadb/data 建一個目錄作為和容器的對映目錄
5 docker run --name mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=輸入資料庫root使用者的密碼 -v /data/mariadb/data:/var/lib/mysql -d mariadb
--name啟動容器設定容器名稱為mariadb
-p設定容器的3306埠對映到主機3306埠
-e MYSQL_ROOT_PASSWORD設定環境變數資料庫root使用者密碼為輸入資料庫root使用者的密碼
-v設定容器目錄/var/lib/mysql對映到本地目錄/data/mariadb/data
-d後臺執行容器mariadb並返回容器id
6 docker ps -a 檢視容器是否執行
7 docker container update --restart=always 容器id 修改容器為自啟動
8 進入容器docker exec -it 容器Id bash
9 在容器內登入資料庫 mysql -uroot -proot密碼
10 修改遠端登入j及密碼
1、設定遠端登入: MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) 2、修改使用者密碼,以root為例 知道root密碼,需要修改 方法a. 登入資料庫來修改 # mysql -uroot -p /*輸入密碼進入*/ /*第一個方式:直接編輯資料庫欄位*/ MariaDB [(none)]> use mysql; MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root'; MariaDB [mysql]> flush privileges; MariaDB [mysql]> exit /*第二個方式:修改密碼,不用進入mysql*/ MariaDB [(none)]> SET password for 'root'@'localhost'=password('newpassword'); MariaDB [(none)]> exit; 忘記密碼: # systemctl stop mariadb /*先停掉當前的mysql程序,不然執行下一步說程序已經存在*/ # mysqld_safe --skip-grant-tables & /*後臺直接這個mysql,介面中還會出現日誌,直接ctrl+c進入命令列輸入*/ # ps -ef | grep mariadb /*看程序,會突出顯示--skip-grant-tables*/ mysql 3607 3368 0 18:05 pts/0 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock # mysql /*直接進入mysql,不需要密碼等,執行第一步中方法a裡兩種方式中任何一種即可*/ MariaDB [(none)]> use mysql; MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root'; MariaDB [mysql]> flush privileges; MariaDB [mysql]> exit; /*這個時候用引數--skip-grant-tables啟動的mysql已經會要求輸入密碼才能進入了*/ # pkill mysql /*用pkill來殺,kill不死,kill之後自動起來一個*/ # systemctl start mariadb /*啟動正常的mysql*/
MariaDB [(none)]> select host,user,authentication_string from user; ERROR 1046 (3D000): No database selected MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mysql]> select host,user,authentication_string from user; +-----------+-------------+-------------------------------------------+ | Host | User | authentication_string | +-----------+-------------+-------------------------------------------+ | localhost | mariadb.sys | | | localhost | root | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 | | % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | +-----------+-------------+-------------------------------------------+ 3 rows in set (0.001 sec) MariaDB [mysql]> ALTER USER 'root'@'%' IDENTIFIED BY 'xueqing@2020'; Query OK, 0 rows affected (0.002 sec) MariaDB [mysql]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.001 sec) MariaDB [mysql]> select host,user,authentication_string from user; +-----------+-------------+-------------------------------------------+ | Host | User | authentication_string | +-----------+-------------+-------------------------------------------+ | localhost | mariadb.sys | | | localhost | root | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 | | % | root | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 | +-----------+-------------+-------------------------------------------+ 3 rows in set (0.001 sec)