当前位置:Gxlcms > 数据库问题 > [svc][db]mysql日常维护语句

[svc][db]mysql日常维护语句

时间:2021-07-01 10:21:17 帮助过:6人阅读

mysql启动

  1. <code>docker run -p 3306:3306 -v /data/mysql:/var/lib/mysql -v /etc/localtime:/etc/localtime --name mysql5 --restart=always -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6.23 --character-set-server=utf8 --collation-server=utf8_general_ci</code>

建库-建表-插数据

  1. <code>create database bbs;
  2. create table student(id int,name varchar(40));
  3. show create create table student;
  4. desc student;
  5. insert into student values(1,'maotai');</code>

查看命令帮助

  1. <code>MySQL [(none)]> help create</code>

查表结构

  1. <code>- 查看表结构(MySQL [bbs]> help show grants)可以看到语法
  2. MySQL [bbs]> show create table student;
  3. +---------+------------------------------------------------------------------------------------------------------------------------------+
  4. | Table | Create Table |
  5. +---------+------------------------------------------------------------------------------------------------------------------------------+
  6. | student | CREATE TABLE `student` (
  7. `id` int(11) DEFAULT NULL,
  8. `name` varchar(44) DEFAULT NULL
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  10. +---------+------------------------------------------------------------------------------------------------------------------------------+
  11. 1 row in set (0.00 sec)
  12. - 查看表结构
  13. MySQL [bbs]> desc student;
  14. +-------+-------------+------+-----+---------+-------+
  15. | Field | Type | Null | Key | Default | Extra |
  16. +-------+-------------+------+-----+---------+-------+
  17. | id | int(11) | YES | | NULL | |
  18. | name | varchar(44) | YES | | NULL | |
  19. +-------+-------------+------+-----+---------+-------+
  20. 2 rows in set (0.02 sec)</code>

更新用户密码

  1. <code>## 更改mysql密码: mysqladmin
  2. - 为root设置密码
  3. mysqladmin -uroot password 12345678
  4. - 为root修改密码(已有密码)
  5. $ mysqladmin -uroot -p123456 password 12345678
  6. Warning: Using a password on the command line interface can be insecure.
  7. - 为root修改密码(多实例)
  8. $ mysqladmin -uroot -p123456 password 12345678 -S /data/3306/mysql.sock
  9. ## 更改密码: update语句
  10. - 查看表字段
  11. MySQL [(none)]> desc mysql.user
  12. - 查看用户
  13. MySQL [(none)]> select user,host,password from mysql.user;
  14. - 修改密码(明文: 这样是错误的)
  15. MySQL [(none)]> update mysql.user set password='123456' where user='root' and host='%';
  16. Query OK, 1 row affected (0.00 sec)
  17. Rows matched: 1 Changed: 1 Warnings: 0
  18. MySQL [(none)]> select user,host,password from mysql.user;
  19. +------+------+----------+
  20. | user | host | password |
  21. +------+------+----------+
  22. | root | % | 123456 |
  23. +------+------+----------+
  24. 1 row in set (0.00 sec)
  25. - 正确的姿势
  26. MySQL [(none)]> update mysql.user set password=password('123456') where user='root' and host='%';
  27. Query OK, 1 row affected (0.00 sec)
  28. Rows matched: 1 Changed: 1 Warnings: 0
  29. MySQL [(none)]> flush privileges;
  30. Query OK, 0 rows affected (0.03 sec)
  31. 小结:
  32. 1,带where条件
  33. 2,指定password()函数
  34. ## set
  35. - 适合改密码场景
  36. MySQL [(none)]> set password=password('maotai');
  37. Query OK, 0 rows affected (0.00 sec)</code>

[svc][db]mysql日常维护语句

标签:ges   local   mat   null   har   查看命令   结构   多实例   show   

人气教程排行