MySQL command line basic Operations Command

Source: Internet
Author: User
Tags mysql command line

1:
Start or turn off the MySQL service: Service mysqld Start,service mysqld Stop (or/etc/init.d/mysqld start,/etc/init.d/mysqld stop)
2:
Modify MySQL Password: mysql_secure_installation or mysqladmin-u username-p Old password password new password
3:
Displays MySQL version information: select version ();
4:
Display MySQL date information: select Current_date ();
5:
Show MySQL library: show databases;
6:
Create database fucktable character set UTF8 collate=utf8_general_ci;
7:
Delete databases: drop database fucktable;
8:
Switch database: Use fucktable;
9:
Connect mysql:mysql-u user name-P
10:
Quit MySQL interface: Quit or CTRL + C;
11:
Display Data sheet: show tables;
12:
Create a data table: Creating Table Fucktable (
Fuckid Int (ten) unsigned NOT NULL auto_increment,
Fuckname varchar (255) NULL,
Fucktext char (+) Default '-',
Primary KEY (' Fuckid ')
) Engine=innodb default Charset=utf8 collate=utf8_general_ci;
13:
Add field to table: ALTER TABLE fucktable add column ' Fuckcolumn ' decimal (10,2) default 0 after Fucktext;
14:
Modify field: Alter TABLE fucktable ' Fuckcolumn ' fuckcolumn ' decimal (8,2) default 0 comment ' Yoursister ';
15:
Create Fk:create Table Yoursistertable (
Ystid Int (ten) not NULL auto_increment,
Upupfuckid Int (ten) is not NULL,
Primary KEY (' Ystid '),
Constraint UPUPFUCKID_FK foreign KEY (Upupfuckid) references fucktable (Fuckid)
) Engine=innodb default Charset=utf8 collate=utf8_general_ci;
16:
Delete data table: drop table fucktable;
17:
Displays information about creating a database: Show create databases fuckdb;
18:
Displays information for creating a data table: show create TABLE fucktable;
19:
Display data table information: Desc fucktable or Show columns from fucktable;
20:
Data table Add PRIMARY key: ALTER TABLE fucktable add primary key (' Fuckid ', ' fuckxx ');
21st:
Data Table Add unique index: ALTER TABLE fucktable add unique ' fuckunique ' (' fuckname ', ' fuckxx ');
22:
Data table Add normal index: ALTER TABLE fucktable add index ' fuckindex ' (' Fucktext ', ' fuckxx ');
23:
Delete PRIMARY key: ALTER TABLE fucktable drop PRIMARY key (' Fuckid ');
24:
Delete unique index: ALTER TABLE fucktable drop unique ' fuckunique ' (' fuckname ');
25:
Delete Normal index: ALTER TABLE fucktable DROP index ' fuckindex ' (' Fucktext ');
26:
Delete field: ALTER TABLE fucktable drop Fucktext;
27:
Modify data table name: ALTER TABLE fucktable rename to yoursistertable;
28:
Export the database (at this point outside the MySQL command line operation):
Mysqldump-u User name-p password--no-data fuckdb > Fuckdb.sql (This is the structure of the database, no data)
Mysqldump-u User name-p password fuckdb > fuckdb.sql (This is the structure of the database, which contains the data of the table)
29:
Export the data table (at this point outside of MySQL command line operation):
Mysqldump-u User name-p password--no-data fuckdb fucktable > Fucktable.sql (This is the structure of the data table, no data)
Mysqldump-u User name-p password fuckdb fucktable > Fucktable.sql (This is the structure of the data table, including the table's data)
30:
Import the database (at this point outside the MySQL command line operation):
mysql-uroot-p123456 FUCKDB < Fuckdb.sql
31:
Import data: Source/root/upload/fuckdb.sql
32:
MySQL partition: Create TABLE Fucktable (
ID Int (TEN) unsigned NOT NULL auto_increment,
Addtime Int (TEN) unsiged not NULL,
Title varchar (255) NOT NULL,
Content text,
Primary KEY (' ID '),
Key ' Addtime ' (' Addtime ')
) Engine=innodb default Charset=utf8 collate=utf8_general_ci
Partition by range (ID) (
Partition P0 values less than (3),
Partition P1 values less than (6),
Partition P2 values less than MaxValue
)
33:
View partition information: SELECT * from information_schema.partitions where table_name= ' fucktable '
34:
Shows the variables available for MySQL: Show variables
35:
MySQL Authorization: Grant all on * * to ' fuckloginname ' @ '% ' identified by ' Fuckpassword '
36:
Duplicate table structure: CREATE table t2 like T1;
37:
Copy table data insert into t2 select field1,field2 from T1;
38:
Modify field properties: Alter TABLE fucktable change ' field ' field ' int (10);
39:
Creating a View: Create View viewtable (field1,field2,field3) as select A.field1,a.field2,b.field3 from A, b;

40: Delete view: Drop view viewtable;

41:mysql preprocessing statements:
Prepare statementname from "select * from fucktable where ID >?";
Set @i=3;
Execute statementname using @i;

42: Delete Preprocessing statement: Drop prepare statementname;

43:auto_increment re-pat: ALTER TABLE fucktable auto_increment=1;

44: Storage:
Delimiter//
Create Proceduce Pfuck ()
Begin
Set @i=1;
While @i <
INSERT into fucktable values (concate (' Test ', @i));
Set @[email protected]+1;
End while;
End//

45: Trigger:
Delimiter//
Create trigger Tfuck before update on fucktable for each row
Begin
Update fuck2table set title=new.title where Title=old.title;
End//

MySQL command line basic Operations Command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.