1. Change environment variables
Enter the /etc/profile file and add the absolute path to MySQL at the end
cd /etc
vim profile
Finally save and exit.
1. Commonly used commands in MySQL
1. Query library
show databases; #不要忘记分号
2.Switch library
use name; #name为需要切换库的名字
3. View Curry’s table
show tables;
4. View the fields in the table
desc tb_name;
5. View the table creation statement
MySQL table creation statement is one of the most basic SQL statements
6. View current users
select user();
7. View the currently used database
select database();
8.Create a library
create database db1 #创建库db1
9.Create table
use db1; create table t1(`id`int(4),`name`char(40));
10. Check the current database version
select version();
11. Check the database status
show status
12. Check each parameter
show bariables; show variables like'max_connect%';
13. Modify parameters
set global max_connect_errors=1000; #案例( max_connect_errors)
14. View queue
show processlist;show full processlist;
2. Create users and authorize
1. Authorize
CREATE USER ‘User’@‘%’ IDENTIFIED BY ‘passwd’; //这一句是创建一个名为User的用户,可以从任何主机(%表示通配符)登录MySQL服务器,并且使用passwd作为密码。
GRANT ALL PRIVILEGES ON . TO ‘User’@‘%’ WITH GRANT OPTION; //这一句是给User用户授予所有的权限(ALL PRIVILEGES)在所有的数据库(.)上,并且允许User用户将自己拥有的权限授予给其他用户(WITH GRANT OPTION)。
FLUSH PRIVILEGES; //这一句是刷新权限,使得授权生效。
Query authorization table
show grants;
show grants for User; #查看User这个用户的授权