MySQL is a fully networked cross-platform relational database system, a real multi-user, multi-threaded SQL database server, is also a distributed database management system with client / server architecture. It has the advantages of strong function, simple, easy to manage, fast running, and strong security and reliability, users can use many languages to access the Mysql database, for medium, small application systems is ideal. In addition to supporting standard ANSI SQL statements, it is more important to support a variety of platforms, while the software supports multi-threaded mode on the UNIX system to achieve considerable performance. For users who don't use UNIX, it can run in a system service in the Windows NT system, or run in a normal process on the Windows 95/98 system. On the UNIX / Linux system, MySQL supports multi-threaded operation, so that it can get a considerable performance, and it belongs to the open source code soft.
MySQL is an implementation of a client / server structure, which consists of a server daemnqld and a lot of different client programs and libraries. MySQL performs very high performance, very fast running, and is very good. Database. The official pronunciation of MySQL is "My Ess Que Ell" (not my-sequel).
1. Get mysql
First, you must download MySQL. MySQL's official website is: www.mysql.com, in China's mirroring is: www.freecode.net.cn or: http://www2.linuxforum.net/, you can download mysql's stable version 3.22.32 (as of it The author is published). Its version name is mysql-shareware-3.22.32-win, not only free and there is no so-called "30-day vitality period".
Two. MYSQL installation
(1) Installation under WinXP
To a directory, run the setup program, will prompt the entire installation process. It is installed by default to C: / MySQL. If you want to install some things, as an initiator, you can install it in the default directory. Ok, after installation, enter the c: mysql / bin directory, run the mysqld-shareware.exe file directly under WinXP, normal case, there is no prompt information.
1. Unzip the downloaded file to a temporary directory.
2. Click Setup.exe to install to C: / MySQL (default).
3. Copy mysql_example.cnf to c: my.cnf, turn # basedir = d: / mysql / change to Basedir = C: MySQL.
4. Enter MSDOS to the directory C: mysql / bin.
5. Enter mysqld-shareware -install, this is to start the MySQL database service.
6. MySQLADMIN-U root -p password new password, this is the password to modify the root user (the default password is empty.)
7. Enter mysql -u root -p.
8. Next, enter a new password according to the prompt, and then a few prompt information will appear and the prompt symbol appears:
Welcome to the mysql monitor. Commands end with; or g.
Your MySQL Connection ID IS 6268 TO Server Version: 3.22.32
Type 'Help' for Help.
MySQL>
At this point, you have successfully installed MySQL.
(2) Installation under Windows 2000
1. Select the default directory when installing: c: / mysql
2. Put C: /Mysqlmy-example.cnf Copy is C: my.cnf, and put C: /MysqlibGwinb19.dll Copy to WinntSystem32.3. The method of starting MySQL is:
C: mysql / bin / mysqld-shareware --install
Net Start MySQL
This is so simple, you can start.
4. Change the password of the Super User (root):
C: / mysql / bin / mysql mysql
MySQL> Update User Set Password = Password ('Your Password') SwhereSuser = 'root';
Mysql> quit
C: / mysql / bin / mysqladmin reload
Use the command c: / mysql / bin / mysqlshow to see the test. Here you should display:
---------
| Databases |
---------
| Mysql |
| Test |
---------
Seeing this step will prove that there is no problem.
Come:
C: / mysql / bin / mysqlshow --user = root --password = your password mysql
Here you should display:
Database: mysql
------------
| TABLES |
------------
| Columns_Priv |
| DB |
| Host |
| TABLES_PRIV |
| User |
------------
Everything gets!
5. C: / mysql / bin / mysqladmin version status proc
You should be able to see these versions of information:
MySQLADMIN VER 8.0 Distrib 3.22.32, for Win95 / Win98 on i586
TCX Datakonsult AB, by Monty
Server Version 3.22.32-ShaReware-Debug
Protocol Version 10
Connection Localhost VIA TCP / IP
TCP Port 3306
Uptime: 1 Hour 29 min 30 sec
Threads: 1 Questions: 72 Slow Queries: 0 Opens: 16 Flush Tables: 1 Open Tables: 0 Memory in Use: 16423k max memory used: 16490k
Uptime: 5370 Threads: 1 Questions: 72 Slow Queries: 0 Opens: 16 Flush Tables: 1 Open Tables: 0 MAX ME: 16423K MAX MEMORY USED: 16490K
-- ------ --------- - --------- ---- --- ---- ------------------
| ID | User | Host | DB | Command | TIME | State | Info |
-- ------ --------- - --------- ---- --- ---- ------------------
Three. MYSQL common sense
(1) Field type
1.INT [(m)]
Normal size integer type 2. Double [(M, D)] [Zerofill]
Normal size (double precision) floating point digital type
3.Date
Date type. Supported range is '1000-01-01' to '9999-12-31'. MySQL displays the Date value in 'YYYY-MM-DD' format, but allows you to use strings or numbers to assure the value to the DATE column.
4.char (m)
Set the type of caller, when stored, always fill the right side to the specified length
5.blob text
BLOB or Text type, the maximum length is 65535 (2 ^ 16-1) characters.
6.Varchar
Variable length string type, the most common type.
(2) Basic operation
1: Display database
mysql> show data;
2: The currently selected database,
MySQL> Select Database ();
----------
| Database () |
----------
| Test |
----------
3. The current database contains table information:
mysql> show tables;
---------------------
| TABLES IN TEST |
---------------------
| MyTable1 |
| MyTable2 |
---------------------
4. Get the table structure
mysql> desc myTable1;
------- ------------- ---- ----- --------- - -----
| Field | TYPE | NULL | Key | Default | EXTRA |
------- ------------- ---- ----- --------- - -----
| S1 | VARCHAR (20) | YES | | Null | |
------- ------------- ---- ----- --------- - -----
5. Create a table
The table is one of the most basic elements of the database, and the tables can be independent of each other and can be associated with each other. The basic syntax of the creation table is as follows:
Create Table Table_Name
(Column_name Datatype {Identity | Null | NOT NULL},
...)
The parameter table_name and column_name must meet the requirements of the identifier in the user database, and the parameter DATATYPE is a standard SQL type or the type provided by the user database. Users should use the Non-Null clause to enter data.
Create Table also has some other options, such as creating a temporary table and using the SELECT clause from another table to form a new table. Also, the creation table is the primary key or index of the identifier that can be set with Primary Key, Key, Index. Pay attention to writing: List of full field list in a pair of parentheses. The field name is spaced apart with a comma. Add a space after the comma between fields. There is no comma after the last field name. All SQL statements are ended in semicolons;
example:
Mysql> Create Table Guest (Name Varchar (10), SEX VARCHAR (2), AGE INT (3), Career Varchar (10));
6. Create an index
Indexes for queries for the database. The general database has a variety of indexing schemes, each of which is fine at a particular query class. Index can accelerate the query process of the database. The basic syntax for creating an index is as follows: 10. Data update (1) of the table modifies a field again, pay attention to the syntax again. Text needs an additional number but numbers don't.
MySQL> Update Table01 Set Field03 = 'New Info'SwhereSfield01 = 1;
Query Ok, 1 Row Affected (0.00 sec)
(2) Change multiple fields at a time, remember to use a comma in each updated field.
MySQL> Update Table01 Set Field04 = 19991022, FIELD05 = 062218SwhereSfield01 = 1;
Query Ok, 1 Row Affected (0.00 sec)
(3) Update multiple data at a time
Mysql> Update Table01 Set Field05 = 152901SwhereSfield04> 19990101;
Query OK, 3 ROWS Affected (0.00 sec)
11. Delete data
MySQL> delete from table01swheresfield01 = 3;
Query Ok, 1 Row Affected (0.00 sec)
12. Import Database Table
(1) Create a .SQL file
(2) First generate a library such as Auction.c: / mysql / bin> mysqladmin -u root -p creat auction, will prompt the password and successfully created.
(3) Import an Auction.sql file
C: mysql / bin> mysql -u root -p Auction With the above operation, you can create a database AUCTION and one of the table Auctions. 13. mysql database authorization MySQL> Grant SELECT, INSERT, DELETE, CREATE, DROP on *. * (or test. * / user. * / ..) To user name @localhost Identified by 'password'; Such as: Create a new user account to access the database, you need to do the following: MySQL> GRANT USAGE -> on test. * -> to testuser @ localhost; Query OK, 0 ROWS Affected (0.15 sec) Thereafter, a new user called: Testuser, this user can only connect to the database from localhost and connect to the TEST database. Next, we must specify which operations can be performed by this user: Mysql> Grant Select, Insert, Delete, Update -> on test. * -> to testuser @ localhost; Query OK, 0 ROWS Affected (0.00 SEC) This action enables Testuser to perform SELECT, INSERT, and DELETE and UPDATE query operations in every Test database. Now we end the operation and exit the MySQL client: Mysql> EXIT BYE 14. Authorize MYSQL user password The default user name of the mysql database is "root" (MS SQL Server SA Similar), the password is default. Enter it at the DOS prompt (note, not a MySQL prompt) C: mysql / bin> "MySQLADMIN -U ROOT -P Password NewPassword Enter the original password, because the original password is empty, directly enter, the root user's password is changed to" newpassword ".