【MySQL】RHEL6.5下MySQ编译安装、简单的MySQL操作

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

配置防火墙,开启3306端口、selinux

安装编译工具

1
[root@localhost src] # yum install -y gcc gcc-c++

安装cmake

1
2
3
4
[root@localhost src]# tar zxvf cmake- 2.8 . 0 .tar.gz 
[root@localhost src]# cd cmake- 2.8 . 0
[root@localhost cmake- 2.8 . 0 ]# ./configure 
[root@localhost cmake- 2.8 . 0 ]# make && make install

编译安装MySQL

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
[root@localhost cmake-2.8.0] # cd ..
[root@localhost src] # tar zxvf mysql-5.5.40.tar.gz 
[root@localhost src] # groupadd mysql
[root@localhost src] # useradd -g mysql mysql -s /sbin/nologin 
[root@localhost src] # mkdir -p /data/mysql       
[root@localhost src] # chown -R mysql:mysql /data/mysql
[root@localhost src] # cd mysql-5.5.40
[root@localhost mysql-5.5.40] # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
.....
-- Could NOT  find  Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake /readline .cmake:83 (MESSAGE):
   Curses library not found.  Please  install  appropriate package,
 
       remove CMakeCache.txt and rerun cmake.On Debian /Ubuntu , package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
[root@localhost mysql-5.5.40] # rm CMakeCache.txt 
rm : remove regular  file  `CMakeCache.txt'? y   
[root@localhost mysql-5.5.40] # yum -y install ncurses-devel
[root@localhost mysql-5.5.40] # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
......
Warning: Bison executable not found  in  PATH
-- Configuring  done
-- Generating  done
-- Build files have been written to:  /usr/local/src/mysql-5 .5.40
[root@localhost mysql-5.5.40] # yum -y install Bison
[root@localhost mysql-5.5.40] # make && make install
[root@localhost mysql-5.5.40] # rm -rf /etc/my.cnf   #删除系统默认的配置文件(如果默认没有就不用删除)
[root@localhost mysql-5.5.40] # cd /usr/local/mysql/
[root@localhost mysql] # ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql   #生成mysql系统数据库
[root@localhost mysql] # ln -s /usr/local/mysql/my.cnf /etc/my.cnf
[root@localhost mysql] # cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld    #把Mysql加入系统启动
[root@localhost mysql] # chmod 755 /etc/init.d/mysqld
[root@localhost mysql] # chkconfig mysqld on
[root@localhost mysql] # vim /etc/rc.d/init.d/mysqld 
  46 basedir= /usr/local/mysql
  47 datadir= /data/mysql
  [root@localhost mysql] # vim /etc/profile    #把mysql服务加入系统环境变量:在最后添加下面这一行
  export  PATH=$PATH: /usr/local/mysql/bin
  [root@localhost mysql] # source /etc/profile

把myslq的库文件链接到系统默认的位置,这样在编译类似PHP等软件时可以不用指定mysql的库文件地址。

1
2
3
4
[root@localhost mysql] # ln -s /usr/local/mysql/lib/mysql /lib/mysql
[root@localhost mysql] # ln -s /usr/local/include/mysql /usr/include/mysql
[root@localhost mysql] # mkdir /var/lib/mysql
[root@localhost mysql] # ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

service mysqld startAnother MySQL daemon already running with the same unix socket.

临时解决方法:删除或者改名:/var/lib/mysql/mysql.sock 

yum安装

1
[root@localhost ~] # yum -y install mysql mysql-server  mysql-devel


登陆mysql

1
2
[root@localhost ~] # reboot
[root@localhost ~] # mysql -u root

默认的mysql是没密码的

设置Mysql密码

1
2
[root@localhost ~] # mysqladmin -u root password 'justin'
[root@localhost ~] # mysql -u root -p password 'justin'

mysqladmin就是用来设置密码的工具,-u 指定用户,passwod 后跟要定义的密码,密码需要用单引号或者双引号括起来。如果你没在系统变量$PATH中指定/usr/local/mysql/bin/这个目录,需要在命令前加/usr/local/mysql/bin/

或者以下命令设定改密码:

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
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password  for  the root user.  If you've just installed MySQL, and
you haven't  set  the root password yet, the password will be blank,
so you should just press enter here.
Enter current password  for  root (enter  for  none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y    --设置root密码
New password:
Re-enter  new  password:
Password updated successfully!
Reloading privilege tables..
  ... Success!
By  default , a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created  for
them.  This  is  intended only  for  testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y    --移除匿名用户
  ... Success!
Normally, root should only be allowed to connect from  'localhost' .  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y  --不允许远程通过root登陆
  ... Success!
By  default , MySQL comes  with  a database named  'test'  that anyone can
access.  This  is  also intended only  for  testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y  --移除测试数据库
  - Dropping test database...
  ... Success!
  - Removing privileges on test database...
  ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y    --重新加载特权表
  ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks  for  using MySQL!
[root@localhost ~]#

怎么修改数据库密码?

1
2
3
[root@localhost ~] # mysqladmin -u root -p password "justin"
Enter password:
[root@localhost ~] #

"justin"为需要修改为的密码,Enter password后输入的是原来的密码

    遗忘数据库密码?

a、修改MySQL配置文件,在[mysqld]下任意位置添加一行skip-grant-tables”并重启mysql服务

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~] # cp /etc/my.cnf /etc/my.cnfbak
[root@localhost ~] # vim /etc/my.cnf
25  # The MySQL server
26 [mysqld]
27 port            = 3306
28 socket          =  /var/lib/mysql/mysql .sock
29 skip-grant-tables
30 skip-locking
31 key_buffer_size = 16M
[root@localhost ~] # /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@localhost ~] #

      b、登陆mysql修改root密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~] # mysql -uroot -p
Enter password:   --直接回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection idis 2
Server version: 5.1.71-log Source distribution
Copyright (c) 2000, 2013, Oracle and /oritsaffiliates . All rights reserved.
Oracle is a registered trademark of Oracle Corporation and /orits
affiliates. Other names may be trademarks of their respective
owners.
Type  'help;' or  '\h' forhelp. Type  '\c' to clearthe current input statement.
mysql> use mysql;   --使用mysql数据库
Database changed
mysql> update user setpassword=password( "newpassword" ) where user= "root" ;   --newpassword为新的root密码
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> flush privileges;   --刷新特权表,不需要重启服务就可以是刚才的操作生效
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[root@localhost ~] #

 c、取消刚才在/etc/my.cnf中添加的skip-grant-tables并重启服务后使用newpassword成功登陆mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~] # vim /etc/my.cnf
26 [mysqld]
27 port            = 3306
28 socket          =  /var/lib/mysql/mysql .sock
29  #kip-grant-tables
30 skip-locking
[root@localhost ~] # /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@localhost ~] # mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection idis 2
Server version: 5.1.71-log Source distribution
Copyright (c) 2000, 2013, Oracle and /oritsaffiliates . All rights reserved.
Oracle is a registered trademark of Oracle Corporation and /orits
affiliates. Other names may be trademarks of their respective
owners.
Type  'help;' or  '\h' forhelp. Type  '\c' to clearthe current input statement.
mysql>

修改指定用户密码:

1
2
3
4
5
mysql>  update  mysql. user  set  password = password ( '123' where  User = "user1"  and  host= "localhost" ;
Query OK, 0  rows  affected (0.12 sec)
Rows  matched: 0  Changed: 0  Warnings: 0
 
mysql> flush  privileges ;

例如:如果忘记了zabbix的登陆账户admin密码,也可以通过以下步骤找回:

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
[root@localhost ~] # mysql -uroot -p      #登陆数据库
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql> show databases;                    #查询当前所有的库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows  in  set  (0.02 sec)
  
mysql> use zabbix;                   #进入zabbix数据库
Database changed
mysql> show tables;                  #再查看一下里面有很多张表,admin密码放在users表里面。
+-----------------------+
| Tables_in_zabbix      |
+-----------------------+
| acknowledges          |
| actions               |
| alerts                |
| application_template  |
| applications          |
| auditlog              |
| auditlog_details      |
| autoreg_host          |
| conditions            |
| config                |
| dbversion             |
| dchecks               |
| dhosts                |
| drules                |
| dservices             |
| escalations           |
| events                |
| expressions           |
| functions             |
| globalmacro           |
| globalvars            |
| graph_discovery       |
| graph_theme           |
| graphs                |
| graphs_items          |
| group_discovery       |
| group_prototype       |
groups                 |
history                |
| history_log           |
| history_str           |
| history_str_sync      |
| history_sync          |
| history_text          |
| history_uint          |
| history_uint_sync     |
| host_discovery        |
| host_inventory        |
| hostmacro             |
| hosts                 |
| hosts_groups          |
| hosts_templates       |
| housekeeper           |
| httpstep              |
| httpstepitem          |
| httptest              |
| httptestitem          |
| icon_map              |
| icon_mapping          |
| ids                   |
| images                |
| interface             |
| interface_discovery   |
| item_discovery        |
| items                 |
| items_applications    |
| maintenances          |
| maintenances_groups   |
| maintenances_hosts    |
| maintenances_windows  |
| mappings              |
| media                 |
| media_type            |
| node_cksum            |
| nodes                 |
| opcommand             |
| opcommand_grp         |
| opcommand_hst         |
| opconditions          |
| operations            |
| opgroup               |
| opmessage             |
| opmessage_grp         |
| opmessage_usr         |
| optemplate            |
| profiles              |
| proxy_autoreg_host    |
| proxy_dhistory        |
| proxy_history         |
| regexps               |
| rights                |
| screens               |
| screens_items         |
| scripts               |
| service_alarms        |
| services              |
| services_links        |
| services_times        |
| sessions              |
| slides                |
| slideshows            |
| sysmap_element_url    |
| sysmap_url            |
| sysmaps               |
| sysmaps_elements      |
| sysmaps_link_triggers |
| sysmaps_links         |
| timeperiods           |
| trends                |
| trends_uint           |
| trigger_depends       |
| trigger_discovery     |
| triggers              |
| user_history          |
users                  |                    #users表
| users_groups          |
| usrgrp                |
| valuemaps             |
+-----------------------+
108 rows  in  set  (0.00 sec)
  
mysql>  select  * from  users ;        # 查看表里的字段,admin对应的ID是1
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
| userid |  alias  | name   | surname       |  passwd                            | url | autologin | autologout | lang  | refresh |  type  | theme   | attempt_failed | attempt_ip | attempt_clock | rows_per_page |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
|      1 | Admin | Zabbix | Administrator | 5fce1b3e34b520afeffb37ce08c7cd66 |     |         1 |          0 | zh_CN |      30 |    3 | default |              0 |            |             0 |            50 |
|      2 | guest |        |               | d41d8cd98f00b204e9800998ecf8427e |     |         0 |        900 | en_GB |      30 |    1 | default |              0 |            |             0 |            50 |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
2 rows  in  set  (0.00 sec)
  
mysql>  select  userid, passwd  from  users ;
+--------+----------------------------------+
| userid |  passwd                            |
+--------+----------------------------------+
|      1 | 5fce1b3e34b520afeffb37ce08c7cd66 |        #密码是加密的  
|      2 | d41d8cd98f00b204e9800998ecf8427e |
+--------+----------------------------------+
2 rows  in  set  (0.00 sec)
  
mysql>

重新开个终端,生成一个MD5加密的密码,这里密码设置的是redhat

1
2
3
[root@localhost ~] # echo -n redhat|openssl md5    #-n就表示不输入回车符,不加-n,否则就不是这个结果了。
(stdin)= e2798af12a7a0f4f70b4d69efbc25f4d
[root@localhost ~] #

接着上面的为admin用户设定一个密码

1
2
3
4
5
6
7
8
9
10
11
mysql> update  users  set  passwd = 'e2798af12a7a0f4f70b4d69efbc25f4d'  where userid =  '1' ;
        #或者直接使用update  users set passwd=md5("redhat") where userid='1';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
  
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
  
mysql> quit
Bye
[root@localhost ~] #


mysql基本操作

查询当前所有的库

1
2
3
4
5
6
7
8
9
10
11
12
mysql> show databases;
+ --------------------+
Database            |
+ --------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+ --------------------+
rows  in  set  (0.03 sec)
 
mysql>

查询某个库的表

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
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> show tables;
+ ---------------------------+
| Tables_in_mysql           |
+ ---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
user                       |
+ ---------------------------+
24  rows  in  set  (0.00 sec)
 
mysql>

 查看某个表的字段

1
2
3
4
5
6
7
8
9
10
11
12
mysql>  desc  func;
+ -------+------------------------------+------+-----+---------+-------+
| Field | Type                         |  Null  Key  Default  | Extra |
+ -------+------------------------------+------+-----+---------+-------+
name   char (64)                     |  NO    | PRI |         |       |
| ret   | tinyint(1)                   |  NO    |     | 0       |       |
| dl    |  char (128)                    |  NO    |     |         |       |
| type  | enum( 'function' , 'aggregate' ) |  NO    |     |  NULL     |       |
+ -------+------------------------------+------+-----+---------+-------+
rows  in  set  (0.00 sec)
 
mysql>

查看某个表的表结构(创建表时的详细结构)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql> show  create  table  func;
+ -------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Table  Create  Table                                                                                                                                                                                                                                                                                                                                                    |
+ -------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| func  |  CREATE  TABLE  `func` (
   ` name char (64)  COLLATE  utf8_bin  NOT  NULL  DEFAULT  '' ,
   `ret` tinyint(1)  NOT  NULL  DEFAULT  '0' ,
   `dl`  char (128)  COLLATE  utf8_bin  NOT  NULL  DEFAULT  '' ,
   `type` enum( 'function' , 'aggregate' CHARACTER  SET  utf8  NOT  NULL ,
   PRIMARY  KEY  (` name `)
) ENGINE=MyISAM  DEFAULT  CHARSET=utf8  COLLATE =utf8_bin COMMENT= 'User defined functions'  |
+ -------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row  in  set  (0.00 sec)
 
mysql>

查看当前是哪个用户

1
2
3
4
5
6
7
8
9
mysql>  select  user ();
+ ----------------+
user ()         |
+ ----------------+
| root@localhost |
+ ----------------+
1 row  in  set  (0.00 sec)
 
mysql>

查看当前所在数据库

1
2
3
4
5
6
7
8
9
mysql>  select  database ();
+ ------------+
database () |
+ ------------+
| mysql      |
+ ------------+
1 row  in  set  (0.00 sec)
 
mysql>

创建一个新库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql>  create  database  db1;
Query OK, 1 row affected (0.03 sec)
 
mysql> show databases;
+ --------------------+
Database            |
+ --------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| test               |
+ --------------------+
rows  in  set  (0.00 sec)
 
mysql>

创建一个表

1
2
3
4
5
6
7
8
9
10
11
12
13
mysql>  create  table  t1 ( `id`  int (4), ` name char (40));
Query OK, 0  rows  affected (0.02 sec)
 
mysql>  desc  t1;
+ -------+----------+------+-----+---------+-------+
| Field | Type     |  Null  Key  Default  | Extra |
+ -------+----------+------+-----+---------+-------+
| id    |  int (4)   | YES  |     |  NULL     |       |
name   char (40) | YES  |     |  NULL     |       |
+ -------+----------+------+-----+---------+-------+
rows  in  set  (0.00 sec)
 
mysql>

删除某张表

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
mysql> show databases;
+ --------------------+
Database            |
+ --------------------+
| information_schema |
| db1                |
| mysql              |
| performance_schema |
| test               |
+ --------------------+
rows  in  set  (0.00 sec)
 
mysql> use db1;
Database  changed
mysql> show tables;
Empty  set  (0.00 sec)
mysql>  drop  database  db1;
Query OK, 0  rows  affected (0.23 sec)
 
mysql> show databases;
+ --------------------+
Database            |
+ --------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+ --------------------+
rows  in  set  (0.03 sec)
 
mysql>

查看当前数据库版本

1
2
3
4
5
6
7
8
9
mysql>  select  version();
+ -----------+
| version() |
+ -----------+
| 5.5.40    |
+ -----------+
1 row  in  set  (0.00 sec)
 
mysql>

查看当前系统时间

1
2
3
4
5
6
7
8
9
mysql>  select  current_date , current_time ;
+ --------------+--------------+
current_date  current_time  |
+ --------------+--------------+
| 2014-12-24   | 09:04:01     |
+ --------------+--------------+
1 row  in  set  (0.00 sec)
 
mysql>

查看当前mysql的状态

1
2
3
4
5
6
7
8
mysql> show status;
+ ------------------------------------------+-------------+
| Variable_name                            | Value       |
+ ------------------------------------------+-------------+
| Aborted_clients                          | 0           |
| Aborted_connects                         | 0           |
| Binlog_cache_disk_use                    | 0           |
| Binlog_cache_use                         | 0           |

创建一个普通用户并授权

1
2
3
4
5
6
mysql>  grant  all  on  *.*  to  user1 identified  by  'justin' ;                                           
Query OK, 0  rows  affected (0.03 sec)
 
mysql>flush  privileges ;
Query OK, 0  rows  affected (0.01 sec)
mysql>

all 表示所有的权限(读、写、查询、删除等等操作),*.*前面的*表示所有的数据库,后面的*表示该数据库所有的表,identified by 后面跟密码,用单引号括起来。这里的user1指的是localhost上的user1,如果是给网络上的其他机器上的某个用户授权则这样:

1
2
3
mysql>  grant  all  on  *.*  to  'user2' @ '10.15.24.245'  identified  by  'justin' ;
Query OK, 0  rows  affected (0.00 sec)
mysql>

用户和主机的IP之间有一个@,另外主机IP那里可以用%替代,表示所有主机

1
2
3
4
mysql>  grant  all  on  *.*  to  'user3' @ '%'  identified  by  'justin' ;
Query OK, 0  rows  affected (0.02 sec)
 
mysql> grant  select , delete , update , create , drop  on  *.*  to  'user4' @ '%'  identified  by  '123' ;

数据库/数据表/数据列权限: Alter: 修改已存在的数据表(例如增加/删除列)和索引。
Create: 建立新的数据库或数据表。
Delete: 删除表的记录。
Drop: 删除数据表或数据库。
INDEX: 建立或删除索引。
Insert: 增加表的记录。
Select: 显示/搜索表的记录。
Update: 修改表中已存在的记录。

全局管理MySQL用户权限:

file: 在MySQL服务器上读写文件。
PROCESS: 显示或杀死属于其它用户的服务线程。
RELOAD: 重载访问控制表,刷新日志等。
SHUTDOWN: 关闭MySQL服务。

特别的权限:

ALL: 允许做任何事(和root一样)。
USAGE: 只允许登录--其它什么也不允许做

查看某用户权限:

1
2
3
4
5
6
7
8
9
mysql> show grants  for  user1;
+ ---------------------------------------------------------------------------------------------------------------+
| Grants  for  user1@%                                                                                            |
+ ---------------------------------------------------------------------------------------------------------------+
GRANT  ALL  PRIVILEGES  ON  *.*  TO  'user1' @ '%'  IDENTIFIED  BY  PASSWORD  '*418F5110126E965257925334DE2CECD97AE332B5'  |
+ ---------------------------------------------------------------------------------------------------------------+
1 row  in  set  (0.00 sec)
 
mysql>

删除某个用户:

1
2
3
4
5
6
7
8
9
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>  delete  from  user   where  user = 'user1'  and  host= 'localhost' ;
Query OK, 0  rows  affected (0.01 sec)
 
mysql> flush  privileges ;





本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1354088,如需转载请自行联系原作者

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL8.0生产环境二进制标准安装
MySQL8.0生产环境二进制标准安装
|
2月前
|
安全 关系型数据库 MySQL
Linux(CentOS6)安装MySQL5.6
Linux(CentOS 6)系统上安装MySQL 5.6版本的详细步骤,包括准备数据存放目录、创建用户、下载安装包、初始化数据库、配置服务脚本、设置环境变量等操作。
142 1
|
2月前
|
关系型数据库 MySQL Java
centos7安装mysql教程及Navicat平替软件
【8月更文挑战第17天】本教程详述CentOS 7上安装MySQL的过程。首先确保移除任何预装的MySQL组件,然后通过wget获取并安装MySQL的YUM源。可以选择安装特定版本如5.7或8.0。安装MySQL服务器后,启动服务并查找初始密码。登录MySQL后应立即更改密码,并可根据需要设置远程访问权限。此外,还推荐使用免费开源的DBeaver作为数据库管理工具,提供了安装步骤以方便管理和操作MySQL数据库。
|
16天前
|
存储 SQL 关系型数据库
MySQL的安装&数据库的简单操作
本文介绍了数据库的基本概念及MySQL的安装配置。首先解释了数据库、数据库管理系统和SQL的概念,接着详细描述了MySQL的安装步骤及其全局配置文件my.ini的调整方法。文章还介绍了如何启动MySQL服务,包括配置环境变量和使用命令行的方法。最后,详细说明了数据库的各种操作,如创建、选择和删除数据库的SQL语句,并提供了实际操作示例。
58 13
MySQL的安装&数据库的简单操作
|
8天前
|
关系型数据库 MySQL Linux
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
在Linux系统中使用tar.xz压缩包安装MySQL数据库的详细步骤。包括下载MySQL压缩包,解压到指定目录,创建mysql用户和组,设置目录权限,初始化MySQL,配置my.cnf文件,启动服务,以及修改root用户密码。此外,还提供了如何设置Windows远程登录MySQL服务器的方法。
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
|
6天前
|
数据采集 中间件 关系型数据库
Mac系统通过brew安装mysql5.7后,启动报错的解决办法
Mac系统通过brew安装mysql5.7后,启动报错的解决办法
18 2
|
8天前
|
关系型数据库 MySQL Linux
Linux 安装 mysql【使用yum源进行安装】
这篇文章介绍了在Linux系统中使用yum源安装MySQL数据库的步骤,包括配置yum源、安装MySQL服务、启动服务以及修改root用户的默认密码。
Linux 安装 mysql【使用yum源进行安装】
|
2月前
|
弹性计算 关系型数据库 MySQL
centos7 mysql安装及配置
本文详细介绍了在阿里云服务器ECS上通过yum源安装MySQL 8.0.12的过程,包括更新yum源、下载并安装MySQL源、解决安装过程中可能遇到的问题等步骤。此外,还介绍了如何启动MySQL服务、设置开机自启、配置登录密码、添加远程登录用户以及处理远程连接异常等问题。适合初学者参考,帮助快速搭建MySQL环境。
159 8
centos7 mysql安装及配置
|
1月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
2月前
|
关系型数据库 MySQL Linux
在Linux中,新安装mysql后怎样提升mysql的安全级别?
在Linux中,新安装mysql后怎样提升mysql的安全级别?
下一篇
无影云桌面