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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
云数据库 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,如需转载请自行联系原作者

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
4月前
|
关系型数据库 应用服务中间件 nginx
Docker一键安装中间件(RocketMq、Nginx、MySql、Minio、Jenkins、Redis)
本系列脚本提供RocketMQ、Nginx、MySQL、MinIO、Jenkins和Redis的Docker一键安装与配置方案,适用于快速部署微服务基础环境。
|
1月前
|
Ubuntu 关系型数据库 MySQL
MySQL源码编译安装
本文详细介绍了MySQL 8.0及8.4版本的源码编译安装全过程,涵盖用户创建、依赖安装、cmake配置、编译优化等步骤,并提供支持多Linux发行版的一键安装脚本,适用于定制化数据库部署需求。
189 4
MySQL源码编译安装
|
1月前
|
Ubuntu 关系型数据库 MySQL
MySQL二进制包安装
本文详细介绍了在多种Linux系统上通过二进制包安装MySQL 8.0和8.4版本的完整过程,涵盖用户创建、glibc版本匹配、程序解压、环境变量配置、初始化数据库及服务启动等步骤,并提供支持多发行版的一键安装脚本,助力高效部署MySQL环境。
197 4
MySQL二进制包安装
|
1月前
|
安全 关系型数据库 MySQL
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
本文详细介绍在openSUSE系统上通过离线RPM包安装MySQL 8.0和8.4版本的完整步骤,包括下载地址、RPM包解压、GPG密钥导入、使用rpm或zypper命令安装及服务启动验证,涵盖初始密码获取与安全修改方法,适用于无网络环境下的MySQL部署。
308 3
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
|
1月前
|
关系型数据库 MySQL Linux
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
本文介绍了在openSUSE系统上通过SUSE资源库安装MySQL 8.0和8.4版本的完整步骤,包括配置国内镜像源、安装MySQL服务、启动并验证运行状态,以及修改初始密码等操作,适用于希望在SUSE系列系统中快速部署MySQL的用户。
166 3
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
|
1月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
290 5
|
2月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
487 16
|
1月前
|
Ubuntu 关系型数据库 MySQL
MySQL包安装 -- Debian系列(离线DEB包安装MySQL)
本文详细介绍了在Ubuntu 24.04、22.04、20.04及Debian 12系统上,通过离线DEB包安装MySQL 8.0和8.4版本的完整步骤。涵盖下载地址、依赖处理、dpkg安装顺序、配置方法及服务启动验证,确保用户可顺利部署MySQL数据库。
489 0
MySQL包安装 -- Debian系列(离线DEB包安装MySQL)
|
1月前
|
运维 Ubuntu 关系型数据库
MySQL包安装 -- Debian系列(Apt资源库安装MySQL)
本文介绍了在Debian系列系统(如Ubuntu、Debian 11/12)中通过APT仓库安装MySQL 8.0和8.4版本的完整步骤,涵盖添加官方源、配置国内镜像、安装服务及初始化设置,并验证运行状态,适用于各类Linux运维场景。
494 0
MySQL包安装 -- Debian系列(Apt资源库安装MySQL)
|
1月前
|
Oracle 关系型数据库 MySQL
MySQL包安装 -- RHEL系列(离线RPM包安装MySQL)
本文详细介绍在Rocky、CentOS、AlmaLinux、openEuler等主流Linux系统上,通过离线RPM包安装MySQL 8.0和8.4版本的完整步骤,涵盖下载、依赖处理、rpm/yum安装、服务启动、密码设置等关键环节,适用于多种企业级环境部署需求。
532 0
MySQL包安装 -- RHEL系列(离线RPM包安装MySQL)

推荐镜像

更多