简单的修改MySQL表中的数据类型。
如何查看已存在的用户授权信息。
目录
简单的修改MySQL表中的数据类型
#替换age的数据类型为int(2)
mysql> desc chengji;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| xuehao | int(6) | NO | | NULL | |
| name | varchar(10) | YES | | NULL | |
| age | int(6) | YES | | NULL | |
| address | varchar(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> alter table chengji modify column age int(2);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc chengji;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| xuehao | int(6) | NO | | NULL | |
| name | varchar(10) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
| address | varchar(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
在test表中新增name列,数据类型为varchar(10)
alter table test add context_time datetime not NULL;
mysql> create table aa (id int(10) not null primary key);
Query OK, 0 rows affected (0.07 sec)
mysql> desc aa;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(10) | NO | PRI | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql> alter table aa add name varchar(10);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc aa;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(10) | NO | PRI | NULL | |
| name | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Mysql将某个字段修改为null(从不允许为空not null修改为 null)
Mysql将某个字段修改为null(从不允许为空not null修改为 null)
alter table 表 modify 字段类型
mysql> update tom set address=‘hangzhou’ where id=1;
如何授权用户登录
mysql> grant all privileges on *.* to 'mha'@'192.168.158.10' identified by 'manager';
Query OK, 0 rows affected (0.00 sec)
如何查看已存在的用户授权信息,存放在mysql库里面的user表中
mysql> select host,user,password from mysql.user;
+----------------+-------------+-------------------------------------------+
| host | user | password |
+----------------+-------------+-------------------------------------------+
| localhost | root | |
| client1 | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| client1 | | |
| 192.168.158.% | myslave | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| 192.168.158.% | mha | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
| % | mha@server2 | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
| server2 | mha | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
| 192.168.158.10 | mha | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
| 192.168.158.30 | mha | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
| 192.168.158.20 | mha | *7D2ABFF56C15D67445082FBB4ACD2DCD26C0ED57 |
+----------------+-------------+-------------------------------------------+