linux下mysql基础使用

环境:CentO S 6.9 mysql 5.1
MySQL创建用户
对于MySQL数据库而言,存在一个root超级用户,系统初始化完成之后会自动创建一个root用户,并且没有密码,如下记录对于mysql用户的相关操作
1. 创建一个普通用户
对于创建普通用户可根据如下操作执行:

 mysql>>grant  all on *.*  to 'test'@'localhost' identified by 'test';
 mysql>>flush privileges;

all:表示赋予该用户的权限,select insert update 等。
*.*:表示赋予该用户权限的使用范围。第一个*表示数据库 ,第二个*表示数据表
test:表示创建的用户
localhost:表示用户只限本地使用。
identified by 后跟该用户登录的密码
2. 设置root用户密码

mysql>>use  mysql;
mysql>>update  user  set  password = password('root') where user='root';
mysql>>flush privileges ;

注:亦可通过此方法来修改用户密码
如果忘记root用户密码需要如下操作:

vi /etc/my.cnf skip-grant-tables #在[mysqld]申明后添加 重启mysqld服务
use mysql; #进入数据库修改密码
update user set password = password(‘root’) where user=’root’;
flush privileges ;

3.数据库显示中文乱码
如下方式进入数据库可显示中文

mysql -umail -pmail mail --default-character-set=latin1

查询数据库编码

show variables like 'character%';`

查看数据库连接数

show processlist;

查看用户权限设置

show  status

时间戳

mysql> select unix_timestamp('2018-05-12 20:56:05');
+---------------------------------------+
| unix_timestamp('2018-05-12 20:56:05') |
+---------------------------------------+
|                            1526129765 |
+---------------------------------------+
1 row in set (0.00 sec)

mysql> select from_unixtime(1526129765);
+---------------------------+
| from_unixtime(1526129765) |
+---------------------------+
| 2018-05-12 20:56:05       |
+---------------------------+
1 row in set (0.00 sec)

mysql> 

在mysql 中时间是相对重要的环节,在查询语句中,涉及的一段时间的记录查询就需要通过以上方式解析查询,

mysql> select * from login_log where logintime < '1526129765';
+----+--------------+-------------+------------+------------+---------------------+-------------+---------------+-------------+------------+--------+----------+------+-------+---------+-------------+----------------+
| id | serverip     | remoteip    | logintime  | login_type | loginuser           | loginuserid | logindomainid | logindomain | remoteaddr | isaddr | nodename | iid  | orgid | islogin | login_count | firstlogintime |
+----+--------------+-------------+------------+------------+---------------------+-------------+---------------+-------------+------------+--------+----------+------+-------+---------+-------------+----------------+
|  1 | 192.168.5.14 | 192.168.5.1 | 1526127716 | web        | [email protected]      |           7 |             1 | test.com    |            |      0 |          |    0 |     2 |       1 |           1 |     1526127716 |
|  2 | 192.168.5.14 | 192.168.5.1 | 1526127841 | web        | [email protected]      |           7 |             1 | test.com    |            |      0 |          |    0 |     2 |       1 |           1 |     1526127841 |
|  3 | 192.168.5.14 | 192.168.5.1 | 1526128059 | web        | [email protected]      |           7 |             1 | test.com    |            |      0 |          |    0 |     2 |       1 |           1 |     1526128059 |
|  4 | 192.168.5.14 | 192.168.5.1 | 1526129743 | web        | [email protected] |         738 |             1 | test.com    |            |      0 |          |    0 |     2 |       1 |           1 |     1526129743 |
+----+--------------+-------------+------------+------------+---------------------+-------------+---------------+-------------+------------+--------+----------+------+-------+---------+-------------+----------------+
4 rows in set (0.00 sec)

猜你喜欢

转载自blog.csdn.net/qq_42906907/article/details/81486597