小编给大家分享一下MySQL如何实现下载安装配置及编码设置,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
创新互联建站专注于日喀则企业网站建设,响应式网站,商城网站开发。日喀则网站建设公司,为日喀则等地区提供建站服务。全流程按需设计网站,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务
一、下载mysql
最简单方法,直接输入命令:sudo apt-get install mysql-server。装完已经自动配置好环境变量,可以直接使用mysql的命令。
下载安装过程中会提示输入用户名和密码,非常easy!
注:建议将/etc/apt/source.list中的cn改成us,美国的服务器比中国的快很多。
二、配置mysql
1、启动mysql
2、在mydql>中输入:show variables like 'character%'; 查看编码
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
3、设置为utf8mb4编码(生产上多用次编码)
a、 控制台命令:locate my.cnf 查找mysql配置文件:my.cnf
b、 编辑 my.cnf 文件如下(红色为本人改动):
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8mb4# Here is entries for some specific programs
# The following values assume you have at least 32M ram# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
#
# * Basic Settings
#
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
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
"/etc/mysql/my.cnf" [readonly] 132L, 3675C
4、重启mysql(非常重要)
5、测试配置
在mydql>中输入:show variables like 'character%'; 查看编码应该如下:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
四、修改Xshell编码
1、修改连接编码
xshell中选中要连接的会话=>右击选“属性”=>类别选“终端”=>编码下拉选“unicodeutf-8”=>确定
2、修改Xshell工具栏上“编码”按钮,选择“utf8”
五、修改ubuntu编码
1、查看服务器编码,命令行输入:locale
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=zh_CN
LC_TIME=zh_CN
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=zh_CN
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=zh_CN
LC_NAME=zh_CN
LC_ADDRESS=zh_CN
LC_TELEPHONE=zh_CN
LC_MEASUREMENT=zh_CN
LC_IDENTIFICATION=zh_CN
LC_ALL=
2、修改服务器编码
a、使用管理员权限进入/etc/default/
b、使用vi编辑文件:locale 如下:
LANG="en_US.UTF-8"
LANGUAGE="en_US:"
~
~
3、重启服务器(虚拟机)
4、再次查看服务器编码、命令行输入:locale
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
全部设置为utf-8 成功。
通过以上五部设置,所有编码都设置为统一utf8,就可以再Xshell中输入中文,mysql中也可以输入中文,全部搞定!
看完了这篇文章,相信你对“mysql如何实现下载安装配置及编码设置”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!