docker创建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
主要是为了解决直接创建容器的时候报错:
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
创建nginx容器
sudo docker run --name nginx -p 80:80 -v /home/ray/data/nginx:/usr/share/nginx/html -d nginx:latest
把conf文件也映射出来
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
创建phpmyadmin容器
docker run --name pma -p 58080:80 --link mysql56:db -d phpmyadmin/phpmyadmin
修改 /etc/mysql/mysql.conf.d/my.cnf
文件,设置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的环境变量查看
[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,跳过密码校验
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服务并进入mysql
sudo service mysql restart
mysql
进入mysql之后修改密码:
use mysql;
update user set authentication_string=password('root') where user='root';
flush privileges;
quit;
修改完成之后重启mysql服务sudo service mysql restart
补充内容:使用mysql导入大文件sql时可能会报MySQL server has gone away错误,引用一下文章得以解决:
MySQL server has gone away错误的解决办法
在我们使用mysql导入大文件sql时可能会报MySQL server has gone away错误,该问题是max_allowed_packet配置的默认值设置太小,只需要相应调大该项的值之后再次导入便能成功。该项的作用是限制mysql服务端接收到的包的大小,因此如果导入的文件过大则可能会超过该项设置的值从而导致导入不成功!下面我们来看一下如何查看以及设置该项的值。
查看 max_allowed_packet 的值
show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
可以看到默认情况下该项的大小只有4M,接下来将该值设置成150M(10241024150)
set global max_allowed_packet=157286400;
此时再查看大小
show global variables like 'max_allowed_packet';
通过调大该值,一般来说再次导入数据量大的sql应该就能成功了,如果任然报错,则继续再调大一些就行,请注意通过在命令行中进行设置只对当前有效,重启mysql服务之后则恢复默认值,但可以通过修改配置文件(可以在配置文件my.cnf中添加max_allowed_packet=150M即可)来达到永久有效的目的,可其实我们并不是经常有这种大量数据的导入操作,所以个人觉得通过命令行使得当前配置生效即可,没有必要修改配置文件。