当前位置:Gxlcms > 数据库问题 > mysql学习笔记

mysql学习笔记

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

安装

yum install mysql
yum install mysql-server
yum install mysql-devel

启停

service mysqld start

ps -ef | grep mysqld

root@host# cd /usr/bin
./mysqladmin -u root -p shutdown
Enter password: ******

修改root密码

mysqladmin -u root password "new_password";

[root@host]# mysql -u root -p
Enter password:*******

创建用户

. 方法1:在 mysql 数据库中的 user 表添加新用户

root@host# mysql -u root -p
Enter password:*******
mysql> use mysql;
Database changed

mysql> INSERT INTO user 
          (host, user, password, 
           select_priv, insert_priv, update_priv) 
           VALUES (‘localhost‘, ‘guest‘, 
           PASSWORD(‘guest123‘), ‘Y‘, ‘Y‘, ‘Y‘);
Query OK, 1 row affected (0.20 sec)

mysql> FLUSH PRIVILEGES;

. 方法2:通过SQL的 GRANT 命令

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    -> ON TUTORIALS.*
    -> TO ‘zara‘@‘localhost‘
    -> IDENTIFIED BY ‘zara123‘;

常用命令

. show databases
. use 数据库名
. show tables
. show columns from 表名
. show index from 表名
. SHOW TABLE STATUS LIKE [FROM db_name] [LIKE ‘pattern‘] \G: 该命令将输出Mysql数据库管理系统的性能及统计信息。
. show grants;查看当前用户(自己)权限:
. show grants for dba@localhost; 查看其他 MySQL 用户权限:
. grant all on . to dba@localhost;赋权
. revoke all on . from dba@localhost;撤销权限
. grant select on testdb.* to dba@localhost with grant option; 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 grant option

mysql学习笔记

标签:markdown   查看   cte   evo   option   授权   star   性能   其他   

人气教程排行