Centos6.10安装mysql5.6
# Centos6.10安装mysql5.6
## 安装MySQL服务
[root@mini1 ~]# yum install mysql-server
## 启动MySQL服务
[root@mini1 ~]# service mysqld start
## 查看MySQL服务进程
[root@mini1 ~]# ps -ef | grep mysqld
## 修改mysql的root密码
[root@mini1 ~]# mysql -uroot
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD("123456") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
## 重新登录
[root@mini1 ~]# mysql -uroot -p
Enter password:123456
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT User, Password, Host FROM user;
+------+-------------------------------------------+-----------+
| User | Password | Host |
+------+-------------------------------------------+-----------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | mini1 |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 127.0.0.1 |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | ::1 |
| | | localhost |
| | | mini1 |
+------+-------------------------------------------+-----------+
6 rows in set (0.00 sec)
## 授权root使用123456密码在任何地址都能连接到该mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
## 授权用户root从ip为192.168.1.11的主机连接到mysql服务器,并使用123456作为密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.11' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# mysql 创建数据库,添加用户,用户授权
# 一、创建mysql数据库
# 1.创建数据库语法
--创建名称为“testdb”数据库,并设定编码集为utf8
CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
1
2
2
# 二、创建用户
# 1.新建用户
--创建了一个名为:test 密码为:1234 的用户
create user 'test'@'localhost' identified by '1234';
1
2
2
注意: 此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。
# 2.查询用户
--查询用户
select user,host from mysql.user;
1
2
2
# 3.删除用户
--删除用户“test”
drop user test@localhost ;
--若创建的用户允许任何电脑登陆,删除用户如下
drop user test@'%';
1
2
3
4
2
3
4
# 4.更改密码
--方法1,密码实时更新;修改用户“test”的密码为“1122”
set password for test =password('1122');
--方法2,需要刷新;修改用户“test”的密码为“1234”
update mysql.user set password=password('1234') where user='test'
--刷新
flush privileges;
1
2
3
4
5
6
2
3
4
5
6
# 5.用户分配权限
--授予用户test通过外网IP对数据库“testdb”的全部权限
grant all privileges on 'testdb'.* to 'test'@'%' identified by '1234';
--刷新权限
flush privileges;
--授予用户“test”通过外网IP对于该数据库“testdb”中表的创建、修改、删除权限,以及表数据的增删查改权限
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%';
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 6.查看用户权限
--查看用户“test”
show grants for test;
1
2
2
最后更新时间: 2022/7/23 10:17:11