mysql中utf8字符集的设置及character_set_database属性修改
安装MySQL数据库
(1) 创建mysql用户的账号
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -s /sbin/nologin -g mysql -M mysql
[root@localhost ~]# tail -1 /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
[root@localhost ~]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
(2)获取MySQL二进制软件包
百度云盘:http://pan.baidu.com/s/1hrBCzsC
提取码:4yjf

(3) 采用二进制方式安装MySQL
[root@localhost ~]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32
[root@localhost local]# ln -s mysql-5.5.32 mysql
[root@localhost local]# ls
bin games lib libexec mysql-5.5.32 nginx-1.10.2 share
etc include lib64 mysql nginx sbin src
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
命令如下:
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls -l support-files/*.cnf
-rw-r--r--. 1 7161 wheel 4691 Jun 19 2013 support-files/my-huge.cnf
-rw-r--r--. 1 7161 wheel 19759 Jun 19 2013 support-files/my-innodb-heavy-4G.cnf
-rw-r--r--. 1 7161 wheel 4665 Jun 19 2013 support-files/my-large.cnf
-rw-r--r--. 1 7161 wheel 4676 Jun 19 2013 support-files/my-medium.cnf
-rw-r--r--. 1 7161 wheel 2840 Jun 19 2013 support-files/my-small.cnf
[root@localhost mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
(5)初始化MySQL数据库文件
初始化命令如下:
[root@localhost ~]# mkdir -p /usr/local/mysql/data #建立MySQL数据文件目录
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql #授权mysql用户管理MySQL的安装目录
[root@localhost ~]# yum -y install libaio #光盘源安装依赖包,否则下一步的编译会报错
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
------------
-----------
Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!
以上的命令主要作用是生成如下数据库文件
[root@localhost ~]# tree /usr/local/mysql/data/
/usr/local/mysql/data/
├── mysql
│ ├── columns_priv.frm
│ ├── columns_priv.MYD
│ ├── help_keyword.frm
...以下省略若干...
这些MySQL数据文件是MySQL正确运行所必需的基本数据库文件,其功能是对MySQL权限,状态等进行管理。
2.3.3 初始化故障排错集锦
错误示例1:
usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared ob
#错误原因是没有libaio函数库的支持。需要
yum -y install libaio
错误示例2:
WARNING:The host'mysql'could not be looked up with resolveip
#需要修改主机名解析,使其和uname -n一样,修改后的结果如下:
[root@localhost ~] # grep `uname -n` /etc/hosts
错误示例3:
ERROR:1004Can't create file '/tmp/#sql300e_1_o.frm'(errno:13)
#原因是/tmp目录的权限有问题。
解决办法为处理/tmp目录,如下:
[root@localhost ~]# ls -ld /tmp
drwxrwxrwt. 3 root root 4096 Jul 14 07:56 /tmp
[root@localhost ~]# chmod -R 1777 /tmp/
此故障必须解除,否则,后面会出现登陆不了数据库等问题。
2.4 配置并启动MySQL数据库
(1)设置MySQL启动脚本,命令如下:
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
#拷贝MySQL启动脚本到MySQL的命令路径
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
#使脚本可执行
(2)MySQL二进制默认安装路径是/usr/local/mysql,启动脚本里是/usr/local/mysql。如果安装路径不同,那么脚本里路径等都需要替换
(3)启动MySQL数据库,命令如下:
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
(4)检查MySQL数据库是否启动,命令如下:
[root@localhost mysql]# netstat -antup | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1702/mysqld
如果发现3306端口没起来,请tail -100 /usr/local/mysql/data/主机名.err查看日志信息,看是否有报错信息,然后根据相关错误提示进行调试。经常查看服务运行日志是个很好的习惯,也是高手的习惯。
(5)查看MySQL数据库启动结果日志,命令如下:
[root@localhost mysql]# tail -10 /usr/local/mysql/data/localhost.err
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
170714 8:33:47 InnoDB: Waiting for the background threads to start
170714 8:33:48 InnoDB: 5.5.32 started; log sequence number 0
170714 8:33:48 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
170714 8:33:48 [Note] - '0.0.0.0' resolves to '0.0.0.0';
170714 8:33:48 [Note] Server socket created on IP: '0.0.0.0'.
170714 8:33:49 [Note] Event Scheduler: Loaded 0 events
170714 8:33:49 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.5.32' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
(6)设置MySQL开机自启动,命令如下:
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
提示:也可以将启动命令/etc/init.d/mysqld start 放到/etc/rc.local里面
(7)配置mysql命令的全局使用路径,命令如下:
[root@localhost mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql]# which mysqladmin
/usr/local/bin/mysqladmin
(8)登陆MySQL测试,命令如下:
[root@localhost mysql]# mysql #直接输入命令即可登陆
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
Bye
提示:
MySQL安装完成以后,默认情况下,root账户是无密码的,这个必须要设置。
2.5 MySQL安全配置
(1)为MySQL的root用户设置密码,命令如下:
[root@localhost mysql]# mysqladmin -u root password '123123' #设置密码
[root@localhost mysql]# mysql #无法直接登陆了
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost mysql]# mysql -uroot -p #新的登陆方式
Enter password: #输入设置的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
(2)清理无用的MySQL用户及库,命令如下:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
+------+-----------+
4 rows in set (0.00 sec)
mysql> drop user "root"@"::1";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@"localhost";
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
修改字符集为utf-8
[mysqld] character_set_server=utf8
重启mysql即可
systemctl restart mysqld
mysql中utf8字符集的设置及character_set_database属性修改的更多相关文章
- MySQL中 utf8与utf8mb4的区别
MySQL中 utf8与utf8mb4的区别 一.简介 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在 ...
- MySQL中UTF8编码的数据在cmd下乱码
MySQL中UTF8编码的数据在cmd下乱,在数据库ide中看到的却是中文. 其实,原因是cmd用gbk的格式来显示数据,那么我们只需要将utf-8存储的数据用gbk的格式输出到cmd即可. 解决方法 ...
- mysql中utf8和utf8mb4区别
一.什么是utf8mb4 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在utf8mb4是utf8的超集,除 ...
- 浅谈mysql中utf8和utf8mb4区别
转自:http://ourmysql.com/archives/1402 实践过程中发现有时mysql的字符集会引起故障,所以需要了解下这个知识点. 一.简介 MySQL在5.5.3之后增加了这个u ...
- 清官谈mysql中utf8和utf8mb4区别
清官谈mysql中utf8和utf8mb4区别 发布时间:2015 年 10 月 4 日 发布者: OurMySQL 来源:JavaRanger - 专注JAVA高性能程序开发.JVM.Mysql优化 ...
- mysql中通过my.cnf设置默认字符集utf-8
选项配置 配置文件路径:/full/path/mysql/bin/my.cnf (默认为/etc/my.cnf ) [client] default-character-set=utf8 [mysql ...
- mysql中更改字符集为utf8&&mysql中文输入不了问题解决
写给TT:对不起啦!! 嗯,输入不了中文,大多数问题是mysql的字符集设置的问题,当然,别的问题也有可能, 这里我们用两种方法设置mysql的字符集,图形化工具和命令行的方式(一种操作完即可) 一, ...
- MySQL中字段字符集不同导致索引不能命中
今天写了一个sql,其中涉及的表中的数据量都差不多为50w左右,查询发现用了8s.这个只是测试服上数据,放到正式服上,肯定一运行就挂了. SELECT Orders. NO, GuidNo, Orde ...
- PHP与MYSQL中UTF8 中文排序例子
1. 需要在php数组中用中文排序,但是一般使用utf8格式的文件,直接用asort排序不行.用gbk和gb2312可以.这跟几种格式的编码有关系.gbk和gb2312本身的编码就是用拼音排序的. 代 ...
随机推荐
- MS SQL Server 2014,sa登录失败问题
1.用Windows身份验证登录 2.服务器属性-安全性 3.进入服务,重启所有SQL服务
- Java连载77-Integer常用方法、Integer、int、String三者相互转化、自动装箱、自动拆箱
一.关于Integer中常用的方法 package com.bjpowernode.java_learning; public class D77_1_ { public static void ...
- JavaScript DOM–元素操作
获取元素 根据 ID 获取元素 语法: document.getElementById(id) <div id='time'>2020-01-09</div> <scri ...
- 菜单制作:ul li横向排列
CSS菜单制作 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- AC3 exponent coding
1.overview AC-3编码的audio信号中的频率系数由浮点型数据表示,并将其归一化到0~1之间. transform coefficient由exponent和mantissa组成. 设tr ...
- mysql 同时支持多少连接MYSQL 查看最大连接数和修改最大连接数
MySQL查看最大连接数和修改最大连接数 1.查看最大连接数 show variables like '%max_connections%'; 2.修改最大连接数 set GLOBAL max_con ...
- 洛谷 P3805【模板】manacher算法
题目链接:https://www.luogu.com.cn/problem/P3805 Manacher算法$O(n)$: 求以每个字符为中心的最长回文串的半径:如果要求可以以字符间隙为回文中心,就要 ...
- JavaWeb01-动态网页
01.动态网页的优势 动态网页是在服务器端运行的程序!随不同用户,不同条件 返回不同的结果! 001.交互性:网页会根据用户的要求和选择而动态的改变和现实网页内容! 002.自动更新:无需改变页面的代 ...
- mybatis--MyBatis动态SQL语句
mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类: 1. if 语句 (简单的条件判断) 2. ...
- 手动搭建的react环境中,关于图片引入的问题
react手动搭建的环境,require引进来图片不显示,网页src显示[object module] 解决方案 (1)import引进图片 import anli from './img/anli. ...