Install MySQL under Linux
#需要的安装包 (in chronological order)
libdbi-devel-0.8.1-2.1LIBDBI-0.8.1-2.1LIBDBI-drivers-0.8.1a-1.2.2Perl-dbi-1.52-2. El5perl-dbd-mysql-3.0007-2. El5mysql-5.0. the-4. El5_6.6MySQL-devel-5.0. the-4. El5_6.6MySQL-server-5.0. the-4. El5_6.6MySQL-test-5.0. the-4. El5_6.6MySQL-bench-5.0. the-4. El5_6.6
4. Enter MySQL under the command line
#启动MYSQL
/etc/init.d/mysqld start
#创建一个新用户root, the password is root:
Format: Grant permission on the database name. Table name to user @ Login host identified by "User password";
Select " root123 ";
#实现远程连接
Set where user = ' root '; grant all privileges * to [email protected]'%' " Root ";
#登陆MYSQL
The syntax is as follows: Mysql-u user name-p user Password
Type the command mysql-uroot-p, enter the password after entering, enter 12345, and then enter into the MySQL, MySQL prompt is:
Mysql>
Note that if you are connecting to another machine, you need to add a parameter-H machine IP
#增加新用户
Format: Grant permissions on database. * To User name @ login host identified by "password"
For example, add a user user1 password to Password1, so that it can log on to the computer, and all databases have query, insert, modify, delete permissions. First, use the root user to connect to MySQL, and then type the following command:
Select " Password1 ";
If you want the user to be able to log on to MySQL on any machine, change localhost to "%".
If you do not want to User1 have a password, you can make another command to remove the password.
Select "";
#操作数据库
Log in to MySQL, and then run the following command at the prompt of MySQL, with each command ending with a semicolon.
1. Display the list of databases.
show databases;
The default is two databases: MySQL and test. MySQL inventory in the MySQL system and user rights information, we change the password and the new user, is actually to operate the library.
2. Display the data table in the library:
Use MySQL; Show tables;
3, display the structure of the data table:
describe table name;
4. Build the library and delete the library:
Create database name; drop database name;
5, build the table:
Use library name; CREATE TABLE table name (field list); drop table name;
6. Clear the Table records:
from table name;
7. Display the records in the table:
Select from table name;
#导出和导入数据
1. Export Data:
Mysqldump--opt Test > Mysql.test
Export the database test database to the Mysql.test file, which is a text file
such as: Mysqldump-u root-p123456--databases dbname > Mysql.dbname
is to export the database dbname to the file mysql.dbname.
2. Import data:
Mysqlimport-u root-p123456 < Mysql.dbname.
3. Import text data into the database:
The field data of the text data is separated by the TAB key.
Use test; " file name " into table table name;
#其他操作
1: Use the show statement to find out what database currently exists on the server:
Mysql> SHOW DATABASES;
2:2. Create a database Mysqldata
mysql> CREATE DATABASE Mysqldata;
3: Select the database you created
mysql> use Mysqldata; (press ENTER to appear database changed operation success!)
4: See what tables exist in the current database
Mysql> SHOW TABLES;
5: Create a database table
Mysql> CREATE TABLE MYTABLE (name VARCHAR), * * * CHAR (1));
6: Show the structure of the table:
Mysql> DESCRIBE MYTABLE;
7: Add a record to the table
mysql> INSERT into MYTABLE values ("hyq","M");
8: Loading data into a database table in text mode (for example, D:/mysql.txt)
" D:/mysql.txt " into TABLE MYTABLE;
9: Import. sql File command (for example, D:/mysql.sql)
mysql> usedatabase; MySQL>source d:/mysql.sql;
10: Delete Table
Mysql>drop TABLE MYTABLE;
11: Clear the table
from MYTABLE;
12: Update data in table
set ***="F"where name='hyq'; 2006------ £ happytian Read (6) Comments (0 ) Edit Favorites to 365Key
13: Backing Up the database
Mysqldump-u Root Library name >xxx.data
14: Example 2: Connecting to MySQL on a remote host
Assume that the IP of the remote host is:110.110. 110.110 , the user name is root and the password is abcd123. Type the following command: -h110. 110.110. -uroot-pabcd123 // remote login (Note: You and root can not add space, the other is the same)
3. Quit MySQL command:
Exit (Enter)
Linux MySQL Foundation from installation to basic use