MySql教程

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;

这篇关于mysql常用命令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!