{"id":6322,"date":"2016-10-11T16:30:06","date_gmt":"2016-10-11T08:30:06","guid":{"rendered":"http:\/\/rmohan.com\/?p=6322"},"modified":"2016-10-11T16:30:06","modified_gmt":"2016-10-11T08:30:06","slug":"detailed-mysql-basic-commands","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6322","title":{"rendered":"Detailed MySQL basic commands"},"content":{"rendered":"<p><strong>Detailed MySQL basic commands<\/strong><\/p>\n<p>Format: mysql -h host address -u user name -p User password<\/p>\n<p>1, is connected to the machine on MYSQL.<br \/>\nFirst, open a DOS window, then enter the directory mysql \\ bin, then type the command mysql -u root -p, you lose the password prompt after the carriage return may or may not have a space before the space Note that the user name, but there must be no space before the password, or let re-enter your password.<\/p>\n<p>If you have just installed MYSQL, super-user root no password, so you can directly enter into the MYSQL, MYSQL prompt is: MySQL&gt;<\/p>\n<p>2, to connect to remote host on MYSQL. Suppose the remote host IP is: 110.110.110.110, user name is root, password is abcd123. Type the following command:<br \/>\nMySQL -h110.110.110.110 -u root -p 123; (Note: You can not add a space between u and the root, the other is the same)<\/p>\n<p>3, exit MYSQL command : exit (Enter)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2. Change Password<\/strong><\/p>\n<p>Format: mysqladmin -u username -p password old password new password<\/p>\n<p>1, to add a root password ab12.<br \/>\nFirst, enter the DOS directory mysql \\ bin, then type the following command<br \/>\nmysqladmin -u root -password ab12<br \/>\nNote: Since the beginning of root without a password, so the -p an old password can be omitted.<\/p>\n<p>2, then the root password to djg345.<br \/>\nmysqladmin -u root -p ab12 password djg345<br \/>\n<strong>3, add new users<\/strong><\/p>\n<p>Note: different above and below the MYSQL environment because it is a command, so the back with a semicolon as a command terminator<\/p>\n<p>format:. Grant select on database * to username @ log on the host identified by &#8220;password&#8221;<\/p>\n<p>1, adding a password for the user test1 abc, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First, the root user connected to MYSQL, and then type the following command:<br \/>\nGrant SELECT, INSERT, Update, the Delete ON * * to [Email = test1 @ &#8220;%] test1 @&#8221;% [\/ Email] &#8220;Identified by&#8221; ABC &#8220;;.<\/p>\n<p>But increase in users is very dangerous, you want to know as someone test1 password, then he can log your mysql database and the data you can do whatever the solution, see 2 on the internet on any computer.<\/p>\n<p>2, add a user test2 password is abc, so that he can only log on localhost, and can query the database mydb, insert, modify, delete operations (localhost means the local host, that is, MYSQL database where that host) , so that users know that the use test2 password, he can not directly access the database from the internet, can only be accessed through the web page MYSQL host.<br \/>\nGrant SELECT, INSERT, Update, the Delete oN mydb. * to [Email = test2 @ localhost] test2 @ localhost [\/ email ] identified by &#8220;abc&#8221;;<\/p>\n<p>If you do not want test2 password, you can resort to a command to eliminate the password.<br \/>\nGrant SELECT, INSERT, Update, the Delete mydb ON * to [@ Email = test2. localhost] test2 @ localhost [\/ email ] identified by &#8220;&#8221;;<\/p>\n<p><strong>4.1 Creating a database<\/strong><\/p>\n<p>Note: Creating a first connection Mysql database server before<\/p>\n<p>the command: create database &lt;database name&gt;<\/p>\n<p>Example 1: Create a database called xhkdb the<br \/>\nmysql&gt; create database xhkdb;<\/p>\n<p>Example 2: Creating a database and assigned a user<\/p>\n<p>?CREATE DATABASE database name;<\/p>\n<p>?GRANT the SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON * TO database name, database name @localhost IDENTIFIED BY &#8216;password&#8217;;.<\/p>\n<p>?SET the FOR pASSWORD &#8216;database name&#8217; @ &#8216;localhost&#8217; = OLD_PASSWORD ( &#8216; password&#8217;);<\/p>\n<p>followed by the implementation 3 command to create a complete database. Note: Chinese &#8220;Password&#8221; and &#8220;database&#8221; is the need to set up their own households.<br \/>\n4.2 Displaying Database<\/p>\n<p>Command: show databases (Note: There is a final S)<br \/>\nMySQL&gt; Show Databases;<\/p>\n<p>Note: For longer garbled when displayed, to modify the database default encoding. In the following pages GBK encoding as an example:<\/p>\n<p>1, MYSQL modify configuration files: the my.ini modify inside-Character-SET = default GBK<br \/>\n2, run-time code modification:<br \/>\n?Java Code: jdbc: mysql: \/\/ localhost: 3306 \/ ? the Test useUnicode = to true &amp; characterEncoding = GBK<br \/>\n?PHP Code: header ( &#8220;the Content-the Type: text \/ HTML; charset = GB2312&#8221;);<br \/>\n? C language code: int mysql_set_character_set (MYSQL * mysql, char * csname);<br \/>\nthis function is used for the current connection set the default character set. Csname string specifies a valid character set name. Connection collation becomes the default collation character set. The function of the statement of work is similar to SET NAMES, but it can also set mysql-&gt; charset value, thus affecting the set by mysql_real_escape_string () character set.<\/p>\n<p>&nbsp;<br \/>\n<strong>4.3 Delete Database<\/strong><\/p>\n<p>Command: drop database &lt;database name&gt;<br \/>\nFor example: to delete a database named xhkdb<br \/>\nmysql&gt; drop database xhkdb;<\/p>\n<p>Example 1: Delete an already existing database to determine the<br \/>\nMySQL&gt; the drop DROP DATABASE Database;<br \/>\nQuery the OK, 0 rows affected (0.00 sec)<\/p>\n<p>Example 2 : delete an uncertain existence of the database<br \/>\nMySQL&gt; the drop database DROP dATABASE;<br \/>\neRROR 1008 (HY000): the drop of can not database &#8216;drop_database&#8217;; database does not the exist<br \/>\n\/\/ error, can not be deleted &#8216;drop_database&#8217; database, which does not exist .<br \/>\nMySQL&gt; Database the drop DROP DATABASE IF EXISTS;<br \/>\nQuery the OK, 0 rows affected, 1 warning (0.00 sec) \/\/ generate a warning Explanation This database does not exist<br \/>\nMySQL&gt; the Create Database DROP DATABASE;<br \/>\nQuery the OK, 1 Row affected (0.00 sec)<br \/>\nMySQL&gt; the drop database if exists drop_database; \/\/ if exists is determined whether the database exists, there is no error<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>&nbsp;<br \/>\n<strong>4.4 database connection<\/strong><\/p>\n<p>Command: use &lt;database name&gt;<\/p>\n<p>Example: If xhkdb database exists, try to access it:<br \/>\nMySQL&gt; use xhkdb;<br \/>\nscreen prompts: Database changed<\/p>\n<p>use MySQL statements can notice the db_name database as the default (current) database for subsequent statements. The database remains the default database until the end of the discourse, or until a different release USE statement:<br \/>\nMySQL&gt; USE DB1;<br \/>\nMySQL&gt; the SELECT COUNT (*) the FROM MyTable; # Selects from db1.mytable<br \/>\nMySQL&gt; USE DB2;<br \/>\nMySQL&gt; SELECT COUNT (*) fROM mytable; # selects from db2.mytable<\/p>\n<p>uSE statement for a particular database current mark, will not prevent you from accessing other tables in the database. The following examples from the authors table db1 database access, and access to edit the table from the db2 database:<br \/>\nMySQL&gt; the USE db1;<br \/>\nMySQL&gt; the SELECT AUTHOR_NAME, EDITOR_NAME the FROM author, db2.editor<br \/>\n-&gt; the WHERE author.editor_id = db2.editor.editor_id;<\/p>\n<p>the USE statement is provided for compatibility with Sybase.<\/p>\n<p>Some friends asked, how to exit after the connection. In fact, do not withdraw, after use database, using show databases can query the database for all, if you want to jump to other databases with<br \/>\nuse another database name<br \/>\non it.<\/p>\n<p><strong>4.5 currently selected database<\/strong><\/p>\n<p>Command: MySQL&gt; SELECT Database ();<\/p>\n<p>the MySQL in the SELECT command is similar to other programming languages in print or write, you can use it to display a string, numeric result, math expressions, and so on. How to use the command in MySQL SELECT special features?<\/p>\n<p>1. Display the version of MYSQL<br \/>\nMySQL&gt; SELECT Version ();<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; +<br \/>\n| Version () |<br \/>\n+ &#8212;&#8212; + &#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n| 6.0.4-Alpha-Community Community |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8211; +<br \/>\n1 Row in SET (0.02 sec)<\/p>\n<p>2. displays the current time<br \/>\nMySQL&gt; SELECT now ();<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n| now () |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n| 2009-09-15 22:35:32 |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8211; + &#8212;&#8212;-<br \/>\n1 Row in SET (0.04 sec)<\/p>\n<p>3. To display the date<br \/>\nthe SELECT DAYOFMONTH (CURRENT_DATE);<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; + &#8212;&#8211;<br \/>\n| DAYOFMONTH (CURRENT_DATE) |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; +<br \/>\n| 15 |<br \/>\n+ &#8212;&#8212; + &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n1 Row in SET (0.01 sec)<\/p>\n<p>the SELECT MONTH (CURRENT_DATE);<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8211; + &#8212;&#8212;-<br \/>\n| MONTH (CURRENT_DATE) |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n|. 9 |<br \/>\n+ &#8212;&#8212;&#8212; + &#8212;&#8212;&#8212;&#8212;<br \/>\n1 Row in SET (0.00 sec)<\/p>\n<p>the SELECT YEAR (CURRENT_DATE);<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; +<br \/>\n| YEAR (CURRENT_DATE) |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; +<br \/>\n| 2009 |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8211; +<br \/>\n1 Row in SET (0.00 sec)<\/p>\n<p>4. The display string<br \/>\nMySQL&gt; the SELECT &#8220;welecome to My Blog!&#8221;;<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- +<br \/>\n| welecome to My Blog |!<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- +<br \/>\n| welecome to My Blog |!<br \/>\n+ &#8212;&#8212;&#8212;&#8211; + &#8212;&#8212;&#8212;&#8211;<br \/>\n1 Row in SET (0.00 sec)<\/p>\n<p>5. The calculator when using<br \/>\nSELECT ((4 * 4) \/ 10) + 25;<br \/>\n+ &#8212;&#8212;&#8212;&#8211; + &#8212;&#8212;&#8212;&#8211;<br \/>\n| ((4 * 4) \/ 10) + 25 |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- +<br \/>\n| 26.60 |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- +<br \/>\n1 Row in SET (0.00 sec)<\/p>\n<p>6. The concatenated string<br \/>\nselect CONCAT (f_name, &#8220;&#8221;, l_name)<br \/>\nthe Name the AS<br \/>\nfrom employee_data<br \/>\nthe WHERE title = &#8216;Marketing Executive&#8217;;<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n| the Name |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n| Sehgal monica |<br \/>\n| Hal Simlai |<br \/>\n| Joseph Irvine |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n3 rows in SET (0.00 sec)<br \/>\nNote: this use CONCAT () function is used to character string pick up. In addition, we use the results to previously learned AS column &#8216;CONCAT (f_name, &#8220;&#8221;, l_name)&#8217; played a pseudonym.<\/p>\n<p>&nbsp;<br \/>\n<strong>5.1 Create a data table<\/strong><\/p>\n<p>Command: create table &lt;table name&gt; (&lt;field name 1&gt; &lt;Type 1&gt; [, .. &lt;field name n&gt; &lt;type n&gt;]);<\/p>\n<p>for example, to create a table named MyClass,<br \/>\nField name Digital Type Data Width Is empty Whether the primary key Automatically increase Defaults<br \/>\nid int 4 no primary key auto_increment<br \/>\nname char 20 no<br \/>\nsex int 4 no 0<br \/>\ndegree double 16 Yes<br \/>\nMySQL&gt; the Create the Table MyClass (<br \/>\n&gt; the above mentioned id int (4) Not null Primary Key AUTO_INCREMENT ,<br \/>\n&gt; name char (20) Not null,<br \/>\n&gt; Sex int (4) Not null default &#8216;0&#8217;,<br \/>\n&gt; Double Degree (16,2));<br \/>\n<strong>5.3 Delete Data Sheet<\/strong><\/p>\n<p>Command: drop table &lt;table name&gt;<\/p>\n<p>For example: to delete the table named MyClass table<br \/>\nMySQL&gt; the drop the Table MyClass;<\/p>\n<p>the DROP TABLE to cancel one or more tables. You must have the DROP privilege for each table. All table data and table definitions will be canceled, so use this statement to be careful!<\/p>\n<p>Note: For a table with partitions, DROP TABLE permanently cancel the table definition, cancel each partition and cancel all the data stored in these partitions. DROP TABLE will be canceled and the cancellation of the table associated partition definition (.par) file.<\/p>\n<p>For a non-existent table using IF EXISTS to prevent an error. When using IF EXISTS, for each table that does not exist, it generates a NOTE.<\/p>\n<p>RESTRICT and CASCADE can make it easier for the partition. Currently, RESTRICT and CASCADE not work.<br \/>\n<strong>Table 5.4 insert data<\/strong><\/p>\n<p>Command: insert into &lt;table name&gt; [(&lt;1 field name&gt; [, .. &lt;field name n&gt;])] values (value 1) [, (value n)]<\/p>\n<p>Example: To insert a table MyClass two records, which two record indicates: number of scores named Tom 1 is 96.45, No. 2 named Joan score was 82.99, No. 3 named Wang score was 96.5.<br \/>\nmysql&gt; insert into MyClass values (1 , &#8216;Tom&#8217;, 96.45), (2, &#8216;Joan&#8217;, 82.99), (2, &#8216;Wang&#8217;, 96.59);<\/p>\n<p>Note: insert into each table can only be inserted into a record .<br \/>\n<strong>5.5 data Query table<\/strong><\/p>\n<p>1), to query all rows<br \/>\ncommand: select &lt;Field 1, Field 2, &#8230;&gt; from &lt;table name&gt; where &lt;expression&gt;<br \/>\nFor example: view all the data in the table MyClass<br \/>\nMySQL&gt; SELECT * from MyClass;<\/p>\n<p>2), before the inquiry a few lines of data<br \/>\n, for example: see the table in the first two rows of data MyClass<br \/>\nMySQL&gt; SELECT * from the order by the above mentioned id MyClass limit 0,2;<\/p>\n<p>SELECT with where ships used to find out more accurate and complex data.<br \/>\n<strong>5.6 to delete data in the table<\/strong><br \/>\nCommand: delete from table name where expressions<\/p>\n<p>such as: MyClass delete table records numbered 1<br \/>\nmysql&gt; delete from MyClass where id = 1;<\/p>\n<p>The following is a comparison of before and after the deleted data table.<br \/>\nFirstName LastName Age<br \/>\nPeter Griffin 35<br \/>\nGlenn Quagmire 33<br \/>\nPHP code as an example below to delete &#8220;Persons&#8221; table all LastName = &#8216;Griffin&#8217; records:<br \/>\n&lt;? Php<br \/>\n$ Con = mysql_connect ( &#8220;localhost&#8221;, &#8220;peter&#8221;, &#8220;abc123&#8221;);<br \/>\nif (! $ con)<br \/>\n{<br \/>\ndie ( &#8216;Could not connect:&#8217; mysql_error ().);<br \/>\n}<br \/>\nmysql_select_db ( &#8220;my_db&#8221;, $ con);<br \/>\nmysql_query ( &#8220;DELETE FROM Persons WHERE LastName = &#8216;Griffin'&#8221;); mysql_close ($ con);<br \/>\n?&gt;<br \/>\nAfter this deletion, the table is this:<br \/>\nFirstName LastName Age<br \/>\nGlenn Quagmire 33<\/p>\n<p><strong>5.7 modify the data in the table<\/strong><\/p>\n<p>Syntax: update table set field = new value, &#8230; where conditions<br \/>\nmysql&gt; update MyClass set name = &#8216; Mary&#8217; where id = 1;<\/p>\n<p>example 1: MySQL UPDATE statement is a single table:<br \/>\nthe UPDATE [the LOW_PRIORITY] [IGNORE] tbl_name the SET col_name1 = expr1 [, col_name2 = expr2 &#8230;] [WHERE where_definition] [ORDER BY &#8230;] [LIMIT row_count]<\/p>\n<p>examples of 2: UPDATE statement multi-table:<br \/>\nthe UPDATE [the LOW_PRIORITY] [IGNORE] table_references the SET col_name1 = expr1 [, col_name2 = &#8230; expr2] [the WHERE where_definition]<\/p>\n<p>the uPDATE syntax can be updated with the new values in the original table rows columns. SET clause indicates which columns to modify and what value should be given. WHERE clause specifies which rows should be updated. If no WHERE clause, all rows are updated. If you specify an ORDER BY clause, in accordance with the designated order of rows to be updated. LIMIT clause to a given limit, limit the number of rows that can be updated.<\/p>\n<p><strong>5.8 increase the field<\/strong><\/p>\n<p>Command: the ALTER the Table table add field types other;<br \/>\nfor example: In Table MyClass added a field passtest, of type int (4), the default value is 0<br \/>\nMySQL&gt; the ALTER the Table MyClass add passtest int ( 4 ) default &#8216;0&#8217;<\/p>\n<p>plus index<br \/>\nmysql&gt; alter table table add index index name (field name 1 [, field name 2 &#8230;]);<br \/>\nexample: mysql&gt; alter table employee add index emp_name (name);<\/p>\n<p>plus the primary key index<br \/>\nmysql&gt; alter table table name add primary key (field names);<br \/>\nexample: mysql&gt; alter table employee add primary key (id);<\/p>\n<p>plus a unique constraint index<br \/>\nmysql&gt; alter table table name add unique index name (field name);<br \/>\nexample: mysql&gt; alter table employee add unique emp_name2 (cardnumber);<\/p>\n<p>delete an index<br \/>\nmysql&gt; alter table table name drop index index name;<br \/>\nexample: mysql&gt; alter table employee drop index emp_name;<\/p>\n<p>increase the field:<br \/>\nMySQL&gt; the ALTER tABLE table_name the ADD FIELD_NAME field_type;<\/p>\n<p>modify the original field names and type:<br \/>\nMySQL&gt; the ALTER TABLE table_name the CHANGE old_field_name new_field_name field_type;<\/p>\n<p>delete fields:<br \/>\nthe MySQL the ALTER TABLE table_name the DROP FIELD_NAME;<br \/>\n5.9 modify the table name<\/p>\n<p>Command: rename table the original table to the new table name;<\/p>\n<p>for example: In Table MyClass name changed to YouClass<br \/>\nMySQL&gt; MyClass to the rename the Table YouClass;<\/p>\n<p>When you execute RENAME, you can not have any locked tables or transaction activity. You also need to have the original table ALTER, and DROP privileges, and the CREATE and INSERT privileges on the new table.<\/p>\n<p>If the multi-table rename, MySQL encounters any errors, it will all be renamed renamed the table back, everything will return to its original state.<\/p>\n<p>RENAME TABLE are added in MySQL 3.23.23.<\/p>\n<p>&nbsp;<br \/>\n<strong>6, the backup database<\/strong><\/p>\n<p>DOS command in the [url = file: \/\/ \\\\ mysql \\\\ bin] \\\\ mysql \\\\ bin [\/ url] to the next directory<\/p>\n<p>1. Export the entire database<br \/>\nexport files exist by default mysql \\ bin directory<br \/>\nmysqldump -u user name -p database name&gt; exported file name<br \/>\nmysqldump -u USER_NAME -p123456 database_name&gt; outfile_name.sql<\/p>\n<p>2. export a table<br \/>\nmysqldump -u username -p database name watches&gt; export file name<br \/>\nmysqldump -u user_name -p database_name table_name&gt; outfile_name.sql<\/p>\n<p>3. To export a database structure<br \/>\nthe mysqldump -u USER_NAME -p -d -add-drop-table database_name&gt; outfile_name.sql<br \/>\n-d no data -add-drop-table before each create statement increases the Table a the drop<\/p>\n<p>4. with language parameter derivation<br \/>\nmysqldump -uroot -p -default-character-set = latin1 -set-charset = gbk -skip-opt database_name&gt; outfile_name.sql<\/p>\n<p>example, aaa database backup to a file back_aaa in:<br \/>\n[root @ test1 root] # CD \/ Home \/ Data \/ MySQL<br \/>\n[root @ test1 MySQL] # the mysqldump -u root -p &#8211;opt AAA&gt; back_aaa<br \/>\n7.1 Examples of building a database and build a table of 1<\/p>\n<p>drop database if exists school; \/\/ if there is deleted SCHOOL<br \/>\ncreate database school; \/\/ build libraries SCHOOL<br \/>\nuse School; \/\/ open the library SCHOOL<br \/>\nthe Create the Table Teacher \/\/ build table TEACHER<br \/>\n(<br \/>\nthe above mentioned id int (3) Not null Primary Key AUTO_INCREMENT,<br \/>\nchar name (10) Not null,<br \/>\naddress VARCHAR (50) default &#8216;rmohan&#8217;<br \/>\nyear a Date<br \/>\n); \/\/ build table end<\/p>\n<p>\/\/ Here is the insert field<br \/>\ninsert into teacher values ( &#8220;, &#8216; allen&#8217;, &#8216; one india rajesh&#8217; &#8216;1976-10-10&#8217;);<br \/>\nINSERT INTO Teacher values ( &#8221; &#8216;Jack&#8217;, &#8216;rajesh II&#8217;, &#8216;1975-12-23&#8217;);<\/p>\n<p>If you type the above command at mysql prompt can be, but not convenient debugging.<br \/>\n1, you can write the above command as a text file is assumed to be school.sql, and then copied to the c: \\\\ and state into the DOS directory [url = file: \/\/ \\\\ mysql \\\\ bin] \\\\ mysql \\\\ bin [\/ url] , and then type the following command:<br \/>\nMySQL-uroot&#8211;p password &lt;c: \\\\ school.sql<br \/>\nIf successful, vacated his party without any display; any error, there will be prompt. (The above command has been debugging, as long as you \/\/ uncomment to use).<\/p>\n<p>2, or go to the command line using the mysql&gt; source c: \\\\ school.sql; school.sql files can also be imported in the database.<\/p>\n<p>7.2 Examples of building a database and build a table of 2<\/p>\n<p>drop database if exists school; \/\/ if there is deleted SCHOOL<br \/>\ncreate database school; \/\/ build libraries SCHOOL<br \/>\nuse School; \/\/ open the library SCHOOL<br \/>\nthe Create the Table Teacher \/\/ build table TEACHER<br \/>\n(<br \/>\nthe above mentioned id int (3) Not null Primary Key AUTO_INCREMENT,<br \/>\nchar name (10) Not null,<br \/>\naddress VARCHAR (50) default &#8221; rmohan &#8221;,<br \/>\nyear a Date<br \/>\n); \/\/ build table end<\/p>\n<p>\/\/ Here is the insert field<br \/>\ninsert into teacher values ( &#8221; &#8216; &#8216;, &#8221; john &#8221; , &#8221; in rmohan, a &#8221;, &#8221; 1976-10-10 &#8221;);<br \/>\nINSERT INTO Teacher values ( &#8221; &#8221;, &#8221; Jack &#8221;, &#8221; in rmohan, a &#8221;, &#8221; 1975-12- 23 &#8221;);<\/p>\n<p>Note: under construction table<br \/>\n1, the ID number field is set to a length of 3: int (3); and it is automatically incremented for each record: auto_increment; and can not be empty: not null; and let him become the main field primary key.<\/p>\n<p>2. Set the NAME field length of 10 characters<\/p>\n<p>3, the ADDRESS field length to 50 characters, and the default value of rmohan.<\/p>\n<p>4, YEAR set the date field.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Detailed MySQL basic commands<\/p>\n<p>Format: mysql -h host address -u user name -p User password<\/p>\n<p>1, is connected to the machine on MYSQL. First, open a DOS window, then enter the directory mysql \\ bin, then type the command mysql -u root -p, you lose the password prompt after the carriage return may or may [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72,16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6322"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6322"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6322\/revisions"}],"predecessor-version":[{"id":6323,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6322\/revisions\/6323"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}