docker創(chuàng)建mysql容器:
sudo docker run -p 3308:3306 --name mysql56 -v /home/ray/data/mysql56:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6
主要是為了解決直接創(chuàng)建容器的時(shí)候報(bào)錯(cuò):
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
參考了這位仁兄的文章Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
創(chuàng)建nginx容器
sudo docker run --name nginx -p 80:80 -v /home/ray/data/nginx:/usr/share/nginx/html -d nginx:latest
把conf文件也映射出來(lái)
docker run --name nginx -p 80:80 -v /home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/docker-nginx/log:/var/log/nginx -v /home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -d nginx
創(chuàng)建phpmyadmin容器
docker run --name pma -p 58080:80 --link mysql56:db -d phpmyadmin/phpmyadmin
修改 /etc/mysql/mysql.conf.d/my.cnf文件,設(shè)置MySQL的字符集:
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
default-character-set=utf8
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
init_connect='SET NAMES utf8'
[mysql]
default-character-set=utf8
MySQL的環(huán)境變量查看
[root@MySQL mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.36 |
+-----------+
1 row in set (0.00 sec)
mysql> show variables like 'have%ssl%';
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
+---------------+----------+
2 rows in set (0.00 sec)
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'datadir';
+---------------+-------------------+
| Variable_name | Value |
+---------------+-------------------+
| datadir | /data/mysql_data/ |
+---------------+-------------------+
1 row in set (0.00 sec)
ubuntu下修改mysql5.7的密碼
首先找到my.cnf所在的文件夾
cd /etc/mysql/mysql.conf.d/
備份原始的配置文件
cp mysqld.cnf mysqld.cnf.init
編輯mysql.cnf文件,在skip-external-locking的下一行添加skip-grant-tables,跳過(guò)密碼校驗(yàn)
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
# 在這里添加
skip-grant-tables
重啟mysql服務(wù)并進(jìn)入mysql
sudo service mysql restart
mysql
進(jìn)入mysql之后修改密碼:
use mysql;
update user set authentication_string=password('root') where user='root';
flush privileges;
quit;
修改完成之后重啟mysql服務(wù)sudo service mysql restart
補(bǔ)充內(nèi)容:使用mysql導(dǎo)入大文件sql時(shí)可能會(huì)報(bào)MySQL server has gone away錯(cuò)誤,引用一下文章得以解決:
MySQL server has gone away錯(cuò)誤的解決辦法
在我們使用mysql導(dǎo)入大文件sql時(shí)可能會(huì)報(bào)MySQL server has gone away錯(cuò)誤,該問(wèn)題是max_allowed_packet配置的默認(rèn)值設(shè)置太小,只需要相應(yīng)調(diào)大該項(xiàng)的值之后再次導(dǎo)入便能成功。該項(xiàng)的作用是限制mysql服務(wù)端接收到的包的大小,因此如果導(dǎo)入的文件過(guò)大則可能會(huì)超過(guò)該項(xiàng)設(shè)置的值從而導(dǎo)致導(dǎo)入不成功!下面我們來(lái)看一下如何查看以及設(shè)置該項(xiàng)的值。
查看 max_allowed_packet 的值
show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
可以看到默認(rèn)情況下該項(xiàng)的大小只有4M,接下來(lái)將該值設(shè)置成150M(10241024150)
set global max_allowed_packet=157286400;
此時(shí)再查看大小
show global variables like 'max_allowed_packet';

通過(guò)調(diào)大該值,一般來(lái)說(shuō)再次導(dǎo)入數(shù)據(jù)量大的sql應(yīng)該就能成功了,如果任然報(bào)錯(cuò),則繼續(xù)再調(diào)大一些就行,請(qǐng)注意通過(guò)在命令行中進(jìn)行設(shè)置只對(duì)當(dāng)前有效,重啟mysql服務(wù)之后則恢復(fù)默認(rèn)值,但可以通過(guò)修改配置文件(可以在配置文件my.cnf中添加max_allowed_packet=150M即可)來(lái)達(dá)到永久有效的目的,可其實(shí)我們并不是經(jīng)常有這種大量數(shù)據(jù)的導(dǎo)入操作,所以個(gè)人覺(jué)得通過(guò)命令行使得當(dāng)前配置生效即可,沒(méi)有必要修改配置文件。