Dragon Boat Festival short holiday, summed up these simple MySQL commands
Dragon Boat Festival short holiday is over soon, I believe many friends like me, feel that there is not enough rest, it is over, the rest is in a bit of a hurry.
In my spare time from the manufacturer, I summarized some content about MySQL for you, and now I share it with you.
For beginner MySQL children's shoes, you may need the following simple MySQL commands:
How to determine whether MySQL starts and how to start and shut down MySQL
Service mysql status/start/stop
/ etc/init.d/mysql status/start/stop
Ps-ef | grep mysql
How to log in to MySQL
Mysql [db_name]-u [username]-p [password]-h [hostname | IP]
How to create and delete databases
CREATE DATABASE [IF NOT EXISTS] db_name
[DEFAULT] CHARACTER SET charset_name
| | [DEFAULT] COLLATE collation_name |
DROP DATABASE [IF NOT EXISTS] db_name
How to create and delete tables
CREATE TABLE [IF NOT EXISTS] table_name
Col_name1 DATATYPE,col_name2 DATATYPE,... , CONSTRAINT)
ENGINE=engine_name DEFAULT CHARSET=charset_name
DROP TABLE [IF NOT EXISTS] table_name
How to insert data
INSERT INTO table_name [col_name1,col_name2, … ,]
VALUES (v1Jing v2, … ,)
INSERT INTO table_name [col_name1,col_name2, … ,]
SELECT_STATMENT
How to create a user
Mysql > create user username@'IP' identified by 'your_password'
Mysql > grant all privileges on DB_name.* to username@'IP' identified by 'your_password'
How to change a user's password
Method 1:
Mysqladmin-u root-p [your _ password] password 123456
Method 2:
Mysql > use mysql
Mysql > update user set password=password ('123456') WHERE user='root'
Mysql > flush privileges
Method 3:
Mysql > set password for 'scott'@'localhost'=password (' tiger')
Other simple commands
Check the version of MySQL: select version ()
View the user who is currently logged in to MySQL: select user ()
Check what databases are available under the user: show databases
Use a database: use db_name
View the database name that is currently in use: select database ()
See which tables are available in a database: show tables
View the table structure and create statements: desc table_name; | show create table_name
View the creation statement of the database: show create db_name
View warning:show warnings
View MySQL error: perror xxxx
View server status variables, running server statistics and status metrics: show [session | global] status like'% tables%'
Check the server system variable, and the value of the variable actually used is: show [session | global] variables like'% sql_mode%'
Be careful to check the feedback from MySQL. Don't take it for granted that the command was executed successfully.