Summary of common MySQL commands in Linux
The following are some common mysql commands,
-- Start database service myslqd start; -- enter MySQL-u root-p/mysql-h localhost-u root-p DatabaseName; -- list database show database; -- create database XXXX; -- select database use DatabaseName; -- show table; -- display the table attributes show columns from tablename; -- create database source filename.txt; -- add a field alter table tablename add column filename datatype; -- add multiple fields alter table tablename add column filename1 datatype, add column filename2 datatype; -- add a user grant all On *. * to user @ localhost identity by "password"; -- Query TIME select now (); -- Query user select user (); -- query database version select version (); -- query the currently used database select database (); -- delete the student data in the student_course database to rm-f student_cource/student. * -- backup database (backup database Apple1) MySQLdump-u root-p Apple1> C: \ Apple1.txt -- backup table (back up mytable table in database Apple1) mySQLdump-u root-p mytable> C: \ Apple.txt -- create a temporary table (mytable) create temporary table mytable (id int, address varchar (20), name varchar (20 )); -- before creating a table, determine whether the system has the table create table if not exists mytable (......); -- copy the table structure from an existing table 1 table to table2create table table2 select * from table1 where 1 <> 1; -- copy the table create table table2 select * from table1; -- rename the table name alter table table1 rename as table2; -- modify the Data Type of the column alter table table1 modify ID int unsigned; -- change the column ID type to int unsignedalter table table1 change id sid int unsigned; -- rename column ID to SID and type to int unsigned -- create index alter table table1 add index Ind_id (ID); create index ind_ID on tablename (ID ); create unique index ind_id on tablename (ID); -- delete index drop index ind_id On table1; alter table table1 drop index ind_ID; -- the Union query character is connected with multiple columns 'select concat (ID, ':', name, '=') from table1 ------------------------- the second part -------------------------------- displays the database show database; -- show tables in the database show tables; -- display the data table structure describe tablename; -- display the table record select * from tablename; -- query the user select * from user who can operate MySQL; -- create database databasename -- for example, using MySQL> create database AA; --- create table user AA; mysql> create table table1 (ID int auto_increment not null primary key, name char (6), sex char (6), birthday date) --- insert several records MySQL> insert into AA values ('', 'zhang san', 'mal ', '2017-10-01 '); MySQL> insert into AA values ('', 'Liu Jiajia', 'female ', '2017-10-01 '); -- Verification Result MySQL> select * from AA; -- change the birthday of John to 1971> update AA set birthday = '2017-01-10 'where ID = '1 '; -- delete the record MySQL> delete from AA where ID = '1'; -- delete the table and database mysql> drop table tablename; MySQL> drop database databasename; -- add a universal user. -- format: grant select On database. * to username @ localhost identity by 'Password' the user_1 password is 123456. you can log on to any PC and choose MySQL> grant select, insert update, and delete on *. * to user_1 @ "%" identity by "123456"; -- the username user_2 used to create a database operation on the local machine is 123456 MySQL> grant select, insert update, delete on *. * to user_2 @ localhost identity by "123456"; -- log on to the database MySQL>-u user_1-p-h IP address;
The above is a summary of Common commands used to operate MySQL on Linux operating systems. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!