centOS yum 安装mysql-程序员宅基地

技术标签: linux  

安装MySQL。

[root@sample ~]# yum -y install mysql-server  ← 安装MySQL
[root@sample ~]# yum -y install php-mysql  ← 安装php-mysql

配置MySQL

[root@sample ~]#vim /etc/my.cnf  ← 编辑MySQL的配置文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1  ← 找到这一行,在这一行的下面添加新的规则,让MySQL的默认编码为UTF-8
default-character-set = utf8  ← 添加这一行

然后在配置文件的文尾填加如下语句:

[mysql]
default-character-set = utf8

启动MySQL服务

[root@sample ~]# chkconfig mysqld on  ← 设置MySQL服务随系统启动自启动

[root@sample ~]# chkconfig --list mysqld  ← 确认MySQL自启动
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 如果2--5为on的状态就OK

[root@sample ~]#/etc/rc.d/init.d/mysqld start  ← 启动MySQL服务

Initializing MySQL database:         [ OK ]
Starting MySQL:              [ OK ]
MySQL初始环境设定

[1]为MySQL的root用户设置密码

MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。

[root@sample ~]# mysql -u root  ← 用root用户登录MySQL服务器

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host,password from mysql.user;  ← 查看用户信息
+------+------------------------------+---------------+
| user | host          | password |
+------+------------------------------+---------------+
| root | localhost        |       |  ← root密码为空
| root | sample.centospub.com  |       |  ← root密码为空
|   | sample.centospub.com |       |
|   | localhost       |       |
|root | %                                 |XXX      |
|   |                            |       |
+------+------------------------------+---------------+

4 rows in set (0.00 sec)

mysql> set password for root@localhost=password('在这里填入root密码');  ← 设置root密码
Query OK, 0 rows affected (0.01 sec)

mysql> set password for root@'sample.centospub.com'=password('在这里填入root密码');  ← 设置root密码
Query OK, 0 rows affected (0.01 sec)只有设置了这个才可以,才可以通过数据库来安装网址


mysql> set password for root@'xxx'=password('xxx');  ← 设置root密码
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,password from mysql.user;  ← 查看用户信息
+------+--------------------------------+--------------------------+
| user | host          | password     |
+------+--------------------------------+--------------------------+
| root | localhost        | 19b68057189b027f |  ← root密码被设置
| root | sample.centospub.com   | 19b68057189b027f |  ← root密码被设置
|    | sample.centospub.com   |          |
|    | localhost        |          |
+------+--------------------------------+--------------------------+
4 rows in set (0.01 sec)

mysql> exit  ← 退出MySQL服务器
Bye

然后,测试一下root密码有没有生效。

[root@sample ~]# mysql -u root  ← 通过空密码用root登录

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  ← 出现此错误信息说明密码设置成功

[root@localhost ~]# mysql -u root -h sample.centospub.com  ← 通过空密码用root登录

ERROR 1045 (28000): Access denied for user 'root'@'localhost'  (using password: NO)  ← 出现此错误信息说明密码设置成功

[root@sample ~]#mysql -u root -p  ← 通过密码用root登录
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.  ← 确认用密码能够成功登录
Your MySQL connection id is 5 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

[root@sample ~]# mysql -u root -h sample.centospub.com -p  ← 通过密码用root登录
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.  ← 确认用密码能够成功登录
Your MySQL connection id is 6 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit  ← 退出MySQL服务器
Bye


[2] 删除匿名用户

在MySQL刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。

[root@sample ~]# mysql -u root -p  ← 通过密码用root登录
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host from mysql.user;  ← 查看用户信息
+------+----------------------------+
| user | host         |
+------+----------------------------+
|   | localhost       |
| root | localhost       |
|   | sample.centospub.com |
| root | sample.centospub.com  |
+------+----------------------------+
4 rows in set (0.02 sec)

mysql> delete from mysql.user where user='';  ← 删除匿名用户
Query OK, 2 rows affected (0.17 sec)

mysql> select user,host from mysql.user;  ← 查看用户信息
+------+----------------------------+
| user | host         |
+------+----------------------------+
| root | localhost      |
| root | sample.centospub.com |
+------+----------------------------+
2 rows in set (0.00 sec)

mysql> exit  ← 退出MySQL服务器
Bye

好了,下面都不是必须的了!
测试MySQL


[root@sample ~]# mysql -u root -p  ← 通过密码用root登录
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all privileges on test.* to centospub@localhost  identified by '在这里定义密码';  ← 建立对test数据库有完全操

作权限的名为centospub的用户
Query OK, 0 rows affected (0.03 sec)

mysql> select user from mysql.user where user='centospub';  ← 确认centospub用户的存在与否
+---------+
| user  |
+---------+
| centospub |  ← 确认centospub已经被建立
+---------+
1 row in set (0.01 sec)

mysql> exit  ← 退出MySQL服务器
Bye

[root@sample ~]# mysql -u centospub -p  ← 用新建立的centospub用户登录MySQL服务器
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database test;  ← 建立名为test的数据库
Query OK, 1 row affected (0.00 sec)

mysql> show databases;  ← 查看系统已存在的数据库
+-------------+
| Database |
+-------------+
| test    |
+-------------+
1 row in set (0.00 sec)

mysql> use test  ← 连接到数据库
Database changed

mysql> create table test(num int, name varchar(50));  ← 在数据库中建立表
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;  ← 查看数据库中已存在的表
+-------------------+
| Tables_in_test |
+-------------------+
| test     |
+-------------------+
1 row in set (0.01 sec)

mysql> insert into test values(1,'Hello World!');  ← 插入一个值到表中
Query OK, 1 row affected (0.02 sec)

mysql> select * from test;  ← 查看数据库中的表的信息
+------+-------------------+
| num | name      |
+------+-------------------+
| 1   | Hello World!  |
+------+-------------------+
1 row in set (0.00 sec)

mysql> update test set name='Hello Everyone!';  ← 更新表的信息,赋予新的值
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from test;  ← 查看数据库中的表的信息
+------+----------------------+
| num | name      |
+------+----------------------+
| 1   | Hello Everyone! |  ← 确认被更新到新的值
+------+----------------------+
1 row in set (0.01 sec)

mysql> delete from test where num=1;  ← 删除表内的值
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;  ← 确认删除结果
Empty set (0.01 sec)

mysql> drop table test;  ← 删除表
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;  ← 查看表信息
Empty set (0.00 sec)  ← 确认表已被删除

mysql> drop database test;  ← 删除名为test的数据库
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;  ← 查看已存在的数据库
Empty set (0.01 sec)  ← 确认test数据库已被删除(这里非root用户的关系,看不到名为mysql的数据库)

mysql> exit  ← 退出MySQL服务器
Bye

然后,删除测试用过的遗留用户。

[root@sample ~]# mysql -u root -p  ← 通过密码用root登录
Enter password:  ← 在这里输入密码

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 4.1.20

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> revoke all privileges on *.* from centospub@localhost;  ← 取消centospub用户对数据库的操作权限
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user='centospub' and host='localhost';  ← 删除centospub用户
Query OK, 1 row affected (0.01 sec)

mysql> select user from mysql.user where user='centospub';  ← 查找用户centospub,确认已删除与否
Empty set (0.01 sec)  ← 确认centospub用户已不存在

mysql> flush privileges;  ← 刷新,使以上操作生效
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

 

[root@sample ~]# /etc/rc.d/init.d/httpd restart  ← 重新启动HTTP服务
Stopping httpd:             [ OK ]
Starting httpd:             [ OK ]
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/mecho/article/details/8277453

智能推荐

数据结构——平衡二叉树的判断【递归算法】(C语言)_balance treec语言-程序员宅基地

文章浏览阅读874次。平衡二叉树的判断(左右子树的高度差只能为-1,0,1)#include<stdio.h>#include<stdlib.h>#include<queue>#include <iostream>#define MAXSIZE 10010#define ElemType intusing namespace std;typedef struct BTNode{ ElemType data; BTNode *lchild,*._balance treec语言

msyql中文乱码问题_msyql cli 登录 --default-character-set=charset-程序员宅基地

文章浏览阅读1.8k次。参考:http://hi.baidu.com/ayongs/item/30f784122c8d51a5ffded509http://www.2cto.com/database/201108/101151.htmlhttp://www.laruence.com/2008/01/05/12.htmlmysql5.1参考手册一.mysql字符集MySQ_msyql cli 登录 --default-character-set=charset

图像处理和opencv:矩阵数据类型转换convertTo_图像标记矩阵转化-程序员宅基地

文章浏览阅读1.1k次。函数void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;参数m – 目标矩阵。如果m在运算前没有合适的尺寸或类型,将被重新分配。rtype – 目标矩阵的类型。因为目标矩阵的通道数与源矩阵一样,所以rtype也可以看做是目标矩阵的位深度。如果rtype为负值,..._图像标记矩阵转化

关于级联选择器el-cascader的踩坑及解决_某个el-cascader展开项跑到另一个el-cascade下面-程序员宅基地

文章浏览阅读505次。解决:给级联选择器加key,key的值是:new Date().getTime(),在每次数据改变的时候更新key,即this.keyIndex = new Date().getTime()我的报错使用场景:级联选择器是遍历出来的,数据也是遍历的数组里面的,报错的原因是我删除了option绑定的数组,因为后台接口不需要这个数据。但是这个方法是有默认参数的,当不满足自己的需要,需要传其他参树的时候,搜索的建议面板和原来的dom不是同一个dom。在获取到数据之后,对数据进行整体处理。_某个el-cascader展开项跑到另一个el-cascade下面

IAR、KEIL常见编译报错警告的解决方法(持续更新中)_was declared but never referenced-程序员宅基地

文章浏览阅读6.8k次,点赞2次,收藏38次。“Warning[Pe550]: variable “变量” was set but neverused”原因:变量定义赋值了但从未使用解决:变量定义删了就可以,编译器也不会真的给这个变量分配空间Warning[Pe223]: function “函数名” declared implicitly "原因:这个函数隐式声明。意思是在他调用的地方找不到函数原型。解决:在调用的地方增加相应函数头文件的函数原型申明。"Warning[Pe177]: function “函数名” was.._was declared but never referenced

Java正则表达式学习笔记(二)_java正则匹配数字-程序员宅基地

文章浏览阅读2k次,点赞2次,收藏7次。一:正则表达式应用实例1.1 验证汉字: public static void main(String[] args) { //1.验证汉字 String content="周嘉兴aa教育"; String regExp="^[\u0391-\uffe5]+$"; Pattern pattern=Pattern.compile(regExp); Matcher matcher=pattern.matcher(con_java正则匹配数字

随便推点

ImageMagicK编译--合成图片为gif_magick 合并图像 成 gif-程序员宅基地

文章浏览阅读1.7k次。tar xvfz ImageMagick-6.6.9-5.tar.gzcd ImageMagick-6.6.9-5export CPPFLAGS=-I/home/admin/ImageMagick_build/includeexport LDFLAGS=-L/home/admin/ImageMagick_build/lib./configure --prefix=/home_magick 合并图像 成 gif

[.Net码农].NET Framework 4.5 DataRow 类_.net 声明datarow-程序员宅基地

文章浏览阅读1.1k次。http://msdn.microsoft.com/zh-cn/library/system.data.datarow(v=vs.110).aspx_.net 声明datarow

【山外笔记-计算机网络·第7版】第02章:物理层_物理层的电气连接方式可分为-程序员宅基地

文章浏览阅读1.6k次。本文下载链接:[学习笔记]第02章_物理层-打印版.pdf本章最重要的内容是:(1)物理层的任务。(2)几种常用的信道复用技术。(3)几种常用的宽带接入技术,主要是ADSL和FTTx。一、物理层的基本概念1、物理层简介(1)物理层在连接各种计算机的传输媒体上传输数据比特流,而不是指具体的传输媒体。(2)物理层的作用是尽可能地屏蔽掉传输媒体和通信手段的差异。(3)用于物理层的协议..._物理层的电气连接方式可分为

layer弹窗-程序员宅基地

文章浏览阅读29次。layer.alert(content, options, yes) - 普通信息框它的弹出似乎显得有些高调,一般用于对用户造成比较强烈的关注,类似系统alert,但却比alert更灵便。它的参数是自动向左补齐的。通过第二个参数,可以设定各种你所需要的基础参数,但如果你不需要的话,直接写回调即可。如//eg1layer.alert('只想简单的提示'); //eg..._layer弹窗的优缺点

STM32学习第一章_5. 意法半导体基于()公司的cortex-m内核开发的32位的高性能、低功耗单片机。[-程序员宅基地

文章浏览阅读193次。STM32学习第一章1.什么是STM32?ST是意法半导体公司M是基于ARM公司的Cortex-M内核32是32位单片机因此STM32是意法半导体公司基于ARM公司的Cortex-M内核设计高性能以及低功耗的32位单片机2.什么是ARM?ARM-Advanced RISC Machine ARM是英国一家电子公司的名字ARM敢为天下先,首创了chipless的生产模式,即该公司既不生产芯片,也不设计芯片,而是设计出高效的IP内核,授权给半导体公司使用。ARM提供一系列内核、体系扩展_5. 意法半导体基于()公司的cortex-m内核开发的32位的高性能、低功耗单片机。[

可控交流电流源simulink仿真_controlled current source模块simulink-程序员宅基地

文章浏览阅读2.8k次。两个波形进行叉乘,选用Product模块,受控电流源在simulink模型很多,但需要注意应选用Power system/controlled current source。交流电流源需要通过正弦波形进行叉乘,生成一个受控信号控制受控电流源,向电阻供电。电流波形2为10A,100Hz正弦波,与5A叠加。受控的电流波形1选用10A,50Hz正弦波。此时仿真时间为0-0.6s,蓝色为电压波形,黄色电流波形。输出波形方法同前文,不赘述。_controlled current source模块simulink

推荐文章

热门文章

相关标签