数据库
首页 > 数据库> > mysql常用命令

mysql常用命令

作者:互联网

1. 启动mysql服务: net start mysql
或者
service mysql start
或者
systemctl start mysqld
或者
/etc/init.d/mysqld start
或者
sh $MYSQL_HOME/support-files/mysql.server start
2. 关闭mysql服务: net stop mysql
3. 以root用户登录: mysql -h localhost -u root -p 换行输入密码;
mysql -u devuser -p
4. 创建数据库: create schema [数据库名称] default character set utf8 collate utf8_general_ci;
create database devdatabase;
采用create schema和create database创建数据库的效果一样;
5. 创建用户: CREATE USER 'username'@'host' IDENTIFIED BY 'password';
如: create user 'devuser'@'localhost' identified by '123456';
如: create database boarddatabase default character set utf8 collate utf8_general_ci;
6. 授权: GRANT privileges ON databasename.tablename TO username@host identified by 'password';
其中: @"%" 表示对所有非本地主机授权,不包括localhost;
如: grant all privileges on devdatabase.* to devuser@localhost identified by '123456';
grant all privileges on *.* to 'devuser'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' identified by '123456';
7. flush privileges;--立即启用修改
8. revoke all on *.* from tester;--取消用户所有数据库(表)的所有权限
9. 删除用户: delete from mysql.user where user='devuser';
10. 删除数据库: drop database databasename; 如: drop database 'devuser';
11. 退出命令行: exit;
12. 查看数据库(使用devuser登录): show databases;
13. 切换数据库: use databasename;
如: use devdatabase;

标签:database,数据库,devuser,identified,常用命令,mysql,create
来源: https://www.cnblogs.com/chencoolandclear/p/16560322.html