安装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属性修改的更多相关文章

  1. MySQL中 utf8与utf8mb4的区别

    MySQL中 utf8与utf8mb4的区别 一.简介 ​ MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在 ...

  2. MySQL中UTF8编码的数据在cmd下乱码

    MySQL中UTF8编码的数据在cmd下乱,在数据库ide中看到的却是中文. 其实,原因是cmd用gbk的格式来显示数据,那么我们只需要将utf-8存储的数据用gbk的格式输出到cmd即可. 解决方法 ...

  3. mysql中utf8和utf8mb4区别

    一.什么是utf8mb4 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在utf8mb4是utf8的超集,除 ...

  4. 浅谈mysql中utf8和utf8mb4区别

    转自:http://ourmysql.com/archives/1402  实践过程中发现有时mysql的字符集会引起故障,所以需要了解下这个知识点. 一.简介 MySQL在5.5.3之后增加了这个u ...

  5. 清官谈mysql中utf8和utf8mb4区别

    清官谈mysql中utf8和utf8mb4区别 发布时间:2015 年 10 月 4 日 发布者: OurMySQL 来源:JavaRanger - 专注JAVA高性能程序开发.JVM.Mysql优化 ...

  6. mysql中通过my.cnf设置默认字符集utf-8

    选项配置 配置文件路径:/full/path/mysql/bin/my.cnf (默认为/etc/my.cnf ) [client] default-character-set=utf8 [mysql ...

  7. mysql中更改字符集为utf8&&mysql中文输入不了问题解决

    写给TT:对不起啦!! 嗯,输入不了中文,大多数问题是mysql的字符集设置的问题,当然,别的问题也有可能, 这里我们用两种方法设置mysql的字符集,图形化工具和命令行的方式(一种操作完即可) 一, ...

  8. MySQL中字段字符集不同导致索引不能命中

    今天写了一个sql,其中涉及的表中的数据量都差不多为50w左右,查询发现用了8s.这个只是测试服上数据,放到正式服上,肯定一运行就挂了. SELECT Orders. NO, GuidNo, Orde ...

  9. PHP与MYSQL中UTF8 中文排序例子

    1. 需要在php数组中用中文排序,但是一般使用utf8格式的文件,直接用asort排序不行.用gbk和gb2312可以.这跟几种格式的编码有关系.gbk和gb2312本身的编码就是用拼音排序的. 代 ...

随机推荐

  1. (转)http 之session和cookie

    http://www.cnblogs.com/xuxm2007/archive/2011/12/05/2276705.html Session简介 摘 要:虽然session机制在web应用程序中被采 ...

  2. 【蓝桥杯/算法训练】Sticks 剪枝算法

    剪枝算法 大概理解是通过分析问题,发现一些判断条件,避免不必要的搜索.通常应用在DFS 和 BFS 搜索算法中:剪枝策略就是寻找过滤条件,提前减少不必要的搜索路径. 问题描述 George took ...

  3. iterations 快捷键

    原帖:https://blog.csdn.net/Soinice/article/details/83505198 为了防止删除备份的. iterations 快捷键 Live Templates 其 ...

  4. c# DPI SCale

    public class Screen { /// Primary Screen #region Win32 API [DllImport("user32.dll")] stati ...

  5. 2分钟就能学会的【Google/百度搜索大法】了解一下?

    之前我在知乎回答了「日常生活中有哪些十分钟就能学会并可以终生受用的技能」,现在也整理分享给公众号的朋友们. 作为一个入坑8年国际贸易的老阿姨,真心推荐[google搜索大法](同样适用于百度). 2分 ...

  6. update_jz首项V5.0-Tutorial

    What's New: 增加了4个对话框,用于展示信息.归并条目.剔除条目 增加了可视化统计图形中每个科室(柱形)的统计总数 可视化图形一些颜色调整(无奈在省份很多的条件下一些颜色还不易区分) 下面是 ...

  7. Codeforces Round #530 (Div. 2) D. Sum in the tree 树上贪心

    D. Sum in the tree 题意 给出一颗树,奇数层数的点有值,值代表从1到该点的简单路的权值的和,偶数层数的点权值被擦去了 问所有节点的和的最小可能是多少 思路 对于每一个-1(也就是值未 ...

  8. DSP---TI CCSv5.5.x-Windows安装

    TI CCSv5.5.x(正式版)-Windows版本 国内2013年9月13日首发安装CCSv5.5图示 *请关掉防火墙及杀毒软件进行安装 第一步 第二步 安装程序检测到挂起的重新启动,这可能在安装 ...

  9. springmvc、springboot 参数校验

    参数校验在项目中是必不可少的,不仅前端需要校验,为了程序的可靠性,后端也需要对参数进行有效性的校验.下面将介绍在springmvc或springboot项目中参数校验的方法 准备工作: 引入校验需要用 ...

  10. pycharm pro与你同在

    下载激活码和激活依赖的jar包,地址(https://www.lanzous.com/b00t4aneb密码:67t9)按照步骤操作即可第一步:正确安装 Pycharm 软件(版本2019.1.3 p ...