Mysql--> Base-->001-->mysql Basic operation

Source: Internet
Author: User
Tags mysql commands administrator password

One, MySQL installation

uninstall MySQL First step1    sudoApt-get Autoremove--purge mysql-server-5.02    sudoApt-get Remove mysql-Server3    sudoApt-get Autoremove mysql-Server4    sudoApt-get Remove mysql-Common (very important) Step two: Clean up residual data1Dpkg-l |grep^rc|awk '{print $}'|sudo XargsDpkg-P Step three: install MySQL1    sudoApt-getInstallmysql-Server2    sudoApt-getInstallmysql-Client3    sudoApt-getInstallPhp5-mysql (Install php5-MySQL connects PHP with MySQL) Once the installation is complete, the MySQL server should start automatically. You can check whether the MySQL server is running by running the following command at the terminal prompt:1    sudoNetstat-tap |grepMySQL When you run the command, you can see a line similar to the following: TCP0 0Localhost.localdomain:mysql *:* LISTEN-If the server does not function correctly, you can start it by using the following command:1    sudo/etc/init.d/MySQL Restart Fourth step: Configure Administrator password to enter MySQL1$mysql-uroot-p Administrator Password to configure MySQL Administrator password:1    sudoMysqladmin-u Root Password NewPassword

Second, MySQL basic settings

Second, MySQL basic settings1. Verifying Versionmysqladmin--version2. Check the port used by MySQLsudonetstat-lntup|grep "MySQL"3. Create a MySQL database password (the default password is empty) mysqladmin-u root password password4. mysql starts vim when it is powered on/etc/rc.local Add the following content:/etc/init.d/mysqld Start5. Log in to MySQL database MySQL-uroot-penter Password: (enter password here) Three, MySQL basic operation1. Use <db_name>; #格式为useThe <db_name>; function is to use the data that is currently named Db_name as the default database, and subsequent statements will act on the Db_name database until the end of the segment or the next used <db_name>; the appearance of MySQL>Use MySQL; Reading Table Information forCompletion of table and column namesyou can turn off this feature to get a quicker startup with-adatabase Changedmysql>2. The configuration file configuration file for MySQL is under this path:/etc/mysql/my.cnf3. MySQL basic operation command Use database name select the MySQL database to operate, after using this command all MySQL commands are only for that database show databases lists the database list of MySQL database management system show tables show all tables for the specified database , you need to use the use command before using the command to select the database to manipulate show COLUMNS from datasheet display data table properties, property types, primary key information, whether NULL, default values, and other information show index from data table displays the detailed index information of the data table, Includes primary key (primary key) SHOW table STATUS like datasheet \g This command will output the performance and statistics of the MySQL database management system

Iii. MySQL basic commands

1. View basic operations of database information and tables

1.Selectversion (), current_date; MySQL>Selectversion (), current_date; #查询当前数据库版本以及当前的时间+-------------------------+--------------+| Version () | Current_date |+-------------------------+--------------+|5.5. --0ubuntu0.14.04.1| .-Geneva- -|+-------------------------+--------------+1RowinchSet (0.00sec)2. View table Structure desc table_name;mysql>show tables;+----------------+| Tables_in_test |+----------------+| Students | | Teachers |+----------------+2RowsinchSet (0.00sec) MySQL>desc Teachers;+-------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------------------+------+-----+---------+----------------+|ID|int(Ten) unsigned | NO | PRI | NULL | auto_increment | | name |Char(8)             |     NO | |                NULL | || sex |Char(4)             |     NO | |                NULL | || Age | tinyint3) unsigned |     NO | |                NULL | || Tel |Char( -)            |     YES | |                -       | |+-------+---------------------+------+-----+---------+----------------+5RowsinchSet (0.00sec) MySQL>3Creating tables CREATE table Teachers (ID intUnsigned notNULLAuto_increment Primary Key,nameChar(8) notNULL, sexChar(4) notNULL, age tinyint unsigned notNULL, telChar( -)NULLDefault"-");"ID"is the name of the column;"int"Specifies that the column is of typeint(The value range is 8388608 to 8388607), and in the back we use"unsigned"Is decorated to indicate that the type is unsigned, at which time the range of the column is 0 to 16777215;"Not null"indicates that the value of the column cannot be empty and must be filled, and the default can be null if the property is not specified;"auto_increment"It needs to be used in an integer sequence, and the effect is that if the column is NULL when inserting the data, MySQL will automatically produce a unique identifier value that is larger than the existing values. Only one such value can be in each table and the column must be an indexed column. "PRIMARY Key"indicates that the column is the primary key of the table, the value of this column must be unique, and MySQL will automatically index the column. 4inserting data insert [into] table name [(column name 1, column name 2, column name 3, ...)] VALUES (value 1, value 2, value 3, ...);5. query TableSelectcolumn name from table name [query criteria];where keyword is used to specify the query criteria, in the form of:Selectcolumn name from table name where condition; WHERE clause not only supports"where column name = value"This form of query with a name equal to a value is supported for the operators of general comparison operations, such as =, >, <, >=, <,! =, and some extension operators are [not]NULL、inch, like and so on. You can also combine queries with OR and and for query criteria6. Delete table Delete from table name where delete condition; Delete Row with ID 2: Delete from students whereID=2Delete all data from the table: delete from students;

2, MySQL's Column common operation

ALTER Table: Add, modify, delete table columns, constraints, and other table definitions. View column: DESC table name; ALTER TABLE T_book Rename to BBB; Add column: ALTER TABLE name add column name varchar ( -Delete column: ALTER TABLE table name drop column name; modify column name Mysql:alter table bbb change nnnnn hhint; Modify the column name Sqlserver:exec sp_rename'T_student.name','nn','column'; Modify Column name Oracle:lter table BBB Rename column nnnnn to HHint; Modify column properties: ALTER TABLE T_book modify name varchar ( A);

Mysql--> Base-->001-->mysql Basic operation

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.