First, the introduction I want to use Linux for a long time. Since there is no hard task, there is no system study, recently, because the work needs to use MySQL under Linux. I thought that there was a experience of using SQL Server under Windows. I feel that ISQL installed under Linux should be like a thing. It can have gone a lot of detours when I really install and use mysql. I have a lot of problems. After all, Linux and Windows itself have a big difference. . In order to let the beginners in the study less into the process of learning, get started as soon as possible, write this article, I hope to help you. The Linux environment in this article is Red Hat 9.0, MySQL is 4.0.16. Second, install mysql 1, download MySQL installation file to install MySQL requires the following two files: mysql-server-4.0.16-0.i386.rpm mysql-client-4.0.16-0.i386.rpm download address is: http : //www.mysql.com/downloads/mysql-4.0.html, open this page, find the "Linux X86 RPM Downloads" item, find "Server" and "Client Programs" item, download the above two RPMs file. 2. Installing the MySQL RPM file is the software installation package developed by Red Hat. RPM allows Linux to exempt a lot of complex procedures when installing the package. This command is installing the parameters that are -IVH, where i indicates that the specified RMP package, V represents the details of the installation, H indicates that "#" symbols during the installation show the current installation process. This symbol will continue until the installation is complete. 1) Install the server side running under the directory of two RMP files as follows: [Root @ Test1 local] # rpm -ivh mysql-server-4.0.16-0.i386.rpm displays the following information. Warning: mysql-server-4.0.16-0.i386.rpm: v3 DSA Signature: Nokey, Key ID 5072E1F5 preplay ... ################################################################################################################################################################################################################### ############### [100%] 1: mysql-server #################### ########################. . . . . . (Omitted) / usr / bin / mysqladmin -u root password 'new-password' / usr / bin / mysqladmin -u root -h test1 password 'new-password'. . . . . . (Omitted) Starting MySQLD daemon with databases from / var / lib / mysql As mentioned above, the server is installed. The test is successful to run NetStat to see if the mysql port is open. If the service has been started, the installation is successful. MySQL default port is 3306. [root @ Test1 local] # netstat -nat Active Internet Connections (Servers and Established) Proto Recv-q Send-Q local address foreign address state tcp 0 0.0.0.0:3306 0.0.0.0.0:0:0:3306 0.0.0.0:0:00 listen's display can see mysql The service has been launched.
2) Install the client to run as follows: [root @ Test1 local] # rpm -ivh mysql-client-4.0.16-0.i386.rpm warning: mysql-client-4.0.16-0.i386.rpm: v3 DSA Signature: Nokey, Key ID 5072E1F5 prepaing ... #################################################################################################################################################################################################################################################################################### #### [100%] 1: mysql-client ####################################################################################################################################################################################################################################################### ###### [100%] The display is complete. Use the following command to connect MySQL, whether the test is successful. Third, the command to log in to mysql login mysql is mysql, MySQL's usage syntax is as follows: mysql [-u username] [-h host] [-p [password]] [dbname] UserName and Password are MySQL username and password, respectively, MySQL's initial management account is root, no password, note: This root user is not Linux system user. MySQL default user is root, because there is no password in the initial, just type mysql for the first time. [root @ Test1 local] # mysql welcome to the mysql monitor. Commands end with; or / g. Your mysql connection ID is 1 to Server version: 4.0.16-standard type 'help;' or '/ h' for help. Type '/ c' to clear the buffer. MySQL> "MySQL>" prompt, congratulations, success! The login format after the password is added as follows: mysql -u root -p enter password: (Input Password) where -U follows the username, -P requires the password, enter the password at the input password after entering the password. Note: This mysql file is in / usr / bin directory, with the launch file /etc/init.dc/init.dc/init.dc/init.dc/init.d/mysql, is not a file. 4. Several important directory of MySQL Mysql installation is not installed in a directory after SQL Server, its database file, profile, and command files are very important, especially for Linux's beginners, respectively. Because Linux itself is more complicated, if you don't know the mysql installation directory, you will not talk in-depth learning. Let's take a look at these directorys. 1, database directory / var / lib / mysql / 2, configuration file /usr/share/mysql (Mysql.server command, configuration file) 3, related command / usr / bin (mysqladmin mysqldump, etc.) 4, start script / etc /rc.d/init.d/ (Startup Scripting File MySQL Directory) 5. Modify the login password mysql default has no password, the importance of adding passwords is self-evident. 1, command usr / bin / mysqladmin -u root password 'new-password' format: mysqladmin -u username -P old password Password new password 2, Example 1: Add a password to the root 123456.
Type the following command: [root @ Test1 local] # / usr / bin / mysqladmin -u root password 123456 Note: Because the root is no password, the -p old password can be omitted. 3, the test is modified 1) Do not have a password to log in [root @ Test1 local] # mysql error 1045: Access Denied for user: 'root @ localhost' (using password '(using password') Display error, the password has been modified. 2) Log in with the modified password [root @ Test1 local] # mysql -u root -p Enter Password: (Enter the modified password 123456) Welcome to the mysql monitor. Commands end with; or / g. Your MySQL Connection ID IS 4 TO Server Version: 4.0.16-standard type 'Help;' or '/ h' for help. Type '/ c' to clear the buffer. mysql> success! This is to modify the password through the mysqladmin command, or change the password by modifying the library. 6. Start and stop 1. Start the mysql installation After start the file mysql in the /etc/init.d directory, run the following command when you need to start. [root @ TEST1 INIT.D] # /etc/init.d/mysql start 2, stop / usr / bin / mysqladmin -u root -p Shutdown 3, automatic start 1) Look at whether mysql is in the automatic start list [root @ Test1 local] # / sbin / chkconfig -list 2) Add mysql to your system's launch service group to go to [Root @ Test1 local] # / sbin / chkconfig - add mysql 3) Remove MySQL from the startup service group. [Root @ Test1 local] # / sbin / chkconfig - DEL MYSQL Seven, change the mysql directory mysql default data file storage directory is / var / lib / mysql. If you need to move the directory to / home / data, you need to do the following steps: 1, build the Data directory CD / Home Mkdir Data 2 in the home directory, stop the mysql service process: mysqladmin -u root -P Shutdown 3, VAR / lib / mysql full directory Move to / Home / Data MV / VAR / LIB / MYSQL / HOME / DATA / This will move mySQL's data file to / home / data / mysql 4, find my.cnf configuration file if The / etc / Directory does not have a My.cnf configuration file, please find the * .cnf file to / usr / share / mysql / down, copy one of which is / etc / and renamed my.cnf). The command is as follows: [root @ Test1 mysql] # cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 5, edit MySQL configuration file /etc/my.cnf to ensure that mysql works normally, need Indicates the location of the mysql.sock file. Modify Socket = / var / lib / mysql / mysql.sock The value of the right side is: /Home/mysql/mysql.sock.
The operation is as follows: vi my.cnf (edited by the VI tool, find the following data modification) # The mysql server [mysqld] port = 3306 #socket = /var/lib/mysql/mysql.sock (original content, In order to more stabilize "#" comment this line) socket = /Home/data/mysql/mysql.sock (couple this row) 6, modify the mysql startup script /etc/rc.d/init.d/mysql, the final, need Modify the mysql startup script /etc/rc.d/init.d/mysql, turn the path in the DATADIR = / var / lib / mysql, the path to the right side to your current actual storage: Home / Data / MySQL. [root @ TEST1 ETC] # vi /etc/rc.d/init.d/mysql # datadir = / var / lib / mysql (note this line) DATADIR = / home / data / mysql (plus this line) 7, Restart the mysql service /etc/rc.d/ininit.d/mysql start or use the reboot command to restart Linux If the work is moved properly, it will check it in front of the 7 steps in front. 8. Common operation of mysql Note: After each command in MySQL, you must end. 1, display database mysql> show databases; -------- | Database | ---------- | MySQL | | TEST | ------- - 2 ROWS IN SET (0.04 sec) MySQL just installed with two databases: MySQL and TEST. The MySQL library is very important, there is a MySQL system information, we change your password and add users, actually use the related table in this library. 2, display the table mysql> use mysql in the database; (open the library, open this library for each library, similar to foxpro) Database Changed MySQL> Show Tables; ------------------------------------ ------- | Tables_IN_MYSQL | ----------------- | Column_Priv | | DB | | FUNC | | | | TABLES_PRIV | | | - - -------------- 6 ROWS IN SET (0.01 sec) 3, display the structure of the data sheet: Describe table name; 4, record in the table: SELECT * FROM table name , For example: Displays a record in the User table in the MySQL library. All users who can operate to MySQL users are in this table.
Select * from user; 5, Jian Library: CREATE DATABASE library name; for example: Create a name bit AAA library mysql> Create Databases aaa; 6, Table: Use the table: CREATE TABLE table name (field setting list); For example, in the AAA library just created, the table name is established in the table, and the table is available (serial number, automatic growth), XM (name), XB (gender), csny (born month) four fields for four fields, USE AAA; MYSQL> Create Table Name (ID INT (3) Auto_INCREMENT NOT NULL Primary Key, XM Char (8), XB Char (2), CSNY Date); you can use the describe command to view the original table structure. Mysql> Describe name; ------- -------- ------ -- -------- --- ------------- | Field | Type | NULL | Key | Default | Extra | ------- ------- ---- - ----- -------- ---------------- | ID | INT (3) | | Pri | NULL | Auto_Increment | | XM | Char (8) | YES | | NULL | | | XB | Char (2) | Yes | | Null | | | Csny | Date | Yes | | Null | | ------- - -------- ------ ----- -------------------------- 7 Increase records, for example: increase several related records. Mysql> Insert INTO NAME VALUES ('', 'Zhang San', 'Men,' 1971-10-01 '); MySQL> Insert Into Name Values (' ',' Baiyun ',' Female ',' 1972-05 -20 '); can use the select command to verify the results. MySQL> Select * from name; -- ------ ---- ------------ | ID | XM | XB | CSNY | ---- ------ ------ ------------ | 1 | Zhang San | Male | 1971-10-01 | | 2 | Baiyun | Female | 1972-05-20 | ---- ------ ------ ------------ 8, modified record, for example: The birth year of the three is changed to 1971-01-10 mysql> Update name set csny = '1971-01-10' where xm = 'Zhang 3'; 9, delete record, for example: Delete the record of Zhang San.