linux installation mysql (server and client) under

I. Introduction

I want to use Linux for a long time, because there is no hard task has been no systematic study of the recent nature of the work must be used under Linux MySQL . I thought some experience with SQLServer under Windows, that is installed under Linux MySql should be easy to do, can actually install and use MySQL take a lot of detours, met a lot of problems, after all, Linux and Windows itself is very different. In order for a beginner like me and detours in the learning process, the entry as soon as possible, wrote this article, I hope for your help.

Second, the installation Mysql

1, download the MySQL installation files
to install MySQL requires the following two files:
MySQL-Server-5.0.9-0.i386.rpm   
MySQL-Client-5.0.9-0.i386.rpm
download at: HTTP: // dev .mysql.com / Downloads / MySQL / 5.0.html , open this page, drop down the page to find "linuxx86 RPM downloads" item, find "Server" and "Clientprograms" item, these two rpm files download needed.

2, install MySQL
RPM files are developed by Red Hat software installation package, rpm allows Linux eliminating many complex procedures when installing the package. This command is commonly used parameters during installation -ivh, where i represents the specified rmp package will be installed, installation details when V represents, h represents occurred during installation "#" symbol to show the current installation process. This symbol will continue until after the installation is complete stop.
1) install the server
run the following command in the file directory has two rmp:
[the root @ test1 local] # RPM -ivh the MySQL-Server-5.0.9-0.i386.rpm
following information is displayed.
warning: MySQL-server-5.0.9-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing ... ########################################### [100% ]
. 1: the MySQL-Server ########################################### [
100%] . . . . . . (Not show)
/ usr / bin / mysqladmin -u the root password 'new new-password'
/ usr / bin / mysqladmin -u the root password -H test1 'new new-password'
. . . . . . (Not show)
Starting from mysqld daemon with Databases / var / lib / MySQL
as such information appears, the server installation. Whether the test was successful run netstat to see Mysql port is open, such as opening service has been started, the installation was successful. Mysql default port is 3306.
[the root @ test1 local] # the netstat -nat
the Active Connections the Internet (Servers and ESTABLISHED)
Proto Recv-Q-Q the Send the Local the Address Foreign the Address State   
TCP 0 0 0.0.0.0:3306 0.0.0.0:* the LISTEN   
shown above it can be seenMySQL service has started.
2) install the client
run the following command:
[the root @ test1 local] # RPM -ivh the MySQL-Client-5.0.9-0.i386.rpm
warning: the MySQL-Client-5.0.9-0.i386.rpm: the DSA V3 Signature: NOKEY, Key ID 5072e1f5
the Preparing ... ####################################### #### [100%]
. 1: Client-##################################### the MySQL ###### [100%]
display installed.
Connection with the following command MySQL , whether the test was successful.

Third, log in MySQL

Log in MySQL 's command is MySQL , MySQL uses the following syntax:
MySQL [-u username] [-h Host] [- the p-[password]] [dbname]
username and password are the MySQL user name and password, MySQL initial management account is root, no password Note: the root user is not a user of Linux. MySQL default user is root, not as the initial password, just type the first time into the mysql can be.
[the root @ test1 local] # MySQL
available for purchase to The the MySQL Monitor the Commands endwith The; or \ G..
Your the MySQL Connection ID. 1 to ServerVersion IS: Standard-4.0.16
. the Type 'Help;' or '\ H' Help for the Type ' \ c 'to the Clear at the Buffer.
MySQL>
appeared "mysql>" prompt, Congratulations, installation is successful!
Increased password logon format is as follows:
MySQL -u the root -p
the Enter password: (password)
which is followed by the user name -u, -p require a password, the password in the password after the carriage return.

Note: The mysql file in / usr / bin directory, and start talking behind /etc/init.d/mysql file is not a file.

Four, MySQL several important directory

MySQL after installation unlike SQL Server is installed by default in a directory, its database files are rendered dream ⑴ raise rabbit hairpin raise straight Wren deceive Huang Ke which tracks private veranda ┠ Ke Tuo crowded around Weizhou shallow V plaque miscellaneous Long inux beginners, because Linux itself is more complex directory structure, not sure if MySQL installation directory would be out of the question in-depth study.

Here are just look at these directories.

1, the database directory
/ var / lib / MySQL /

2, configuration file
/ usr / Share / MySQL ( MySQL the .server commands and configuration files)

3, the commands
/ usr / bin (mysqladmin mysqldump commands)

4, startup script
/ etc /rc.d/init.d/ (startup script file mysql directory)
Fifth, modify the login password

MySQL default is no password, password installed to increase the importance of self-evident.

1, the command
usr / bin / mysqladmin -u root password
format: mysqladmin -u username -p old password new password

2, Examples
Example 1: 123456 to add a root.
Type the following command:
[root @ test1 local] # / usr / bin / mysqladmin -u root password123456
Note: Since the beginning of root without a password, so the -p an old password can be omitted.

3, testing whether the modification is successful
1) without a password to log
[root @ test1 local] # MySQL
ERROR 1045: Access denied for the User: 'root @ localhost' (Usingpassword: NO)
error, indicating that the password has been changed.
2) using the modified login password
[root @ test1 local] # MySQL -u root -p
the Enter password: (password 123456 modified after input)
is available for purchase at The to MySQL .. Monitor Commands endwith; or \ G
Your MySQL Connection the above mentioned id IS to ServerVersion 4: 4.0.16-Standard
. Type 'Help;' or '\ H' for Help Type '\ c' to the Clear at The Buffer.
MySQL>
success!
This is modified by mysqladmin password command, but also to change the password by modifying the library.

Sixth, start and stop

1, start the
MySQL startup files after installation is complete MySQL , you can run the following command in the /etc/init.d directory when you need to start.
[root @ test1 the init.d] /etc/init.d/mysql Start #

2, stop
/ usr / bin / mysqladmin -u the root -p the shutdown

. 3, automatic start
1) View mysql whether the automatic startup list
[root @ local test1] # / sbin / chkconfig --list
2) the MySQL add to your system, start the service group to go inside
[root @ test1 local] # / sbin / chkconfig -add MySQL
3) the MySQL removed from the service group will start inside.
[root @ test1 local] # / sbin / chkconfig -del MySQL

Seven, to change MySQL directory

MySQL default data file storage directory / var / lib / mysql. If you want the next directory to / home / data required under the following steps:

   1, the establishment of data directory home directory
   cd / home
   mkdir data

   2, stopped the MySQL service process:
   mysqladmin -u root -p the shutdown

   3, the / var / lib / mysql entire directory to / Home / data
   Music Videos / var / lib / mysql / Home / data /
   this put the MySQL data file to the next / Home / data / MySQL

   . 4, my.cnf configuration file to find
  if no my.cnf configuration file / etc / directory, please find * .cnf file / usr / share / mysql /, where a copy of the / etc / and renamed my.cnf) in. Command is as follows:
   [root @ test1 MySQL] # cp / usr / report this content share / MySQL / My-medium.cnf /etc/my.cnf

   5, edit the MySQL configuration file /etc/my.cnf
   to ensure that MySQL to work properly, you need to specificies the location mysql.sock file. Modify the right socket = / var / lib / mysql / mysql.sock middle row number is: /home/mysql/mysql.sock. As follows:
   vi my.cnf (my.cnf file with the vi editor tool, find the following data modified)
   # at The MySQL Server
    [mysqld]
    Port = 3306
    #socket = /var/lib/mysql/mysql.sock (original content, in order to more secure by "#" comment this line)
    Socket = /home/data/mysql/mysql.sock (this plus line)

   6, modify the MySQL startup script /etc/rc.d/init.d/mysql
  Finally, the need to modify the MySQL startup script /etc/rc.d/init.d/mysql, to which datadir = / var / lib / mysql line, the path to the right of the equal sign into your current actual storage path: home / data / mysql.
   [the root @ test1 etc] # VI /etc/rc.d/init.d/mysql
   # DATADIR = / var / lib / MySQL (comment this line)
   DATADIR = / Home / Data / MySQL (add this line)

   7, restart the MySQL service
   /etc/rc.d/init.d/mysql start
   or restart with a reboot Linux command
   if the move is successful working properly, or in front of the 7-step control check again.

   Eight, MySQL common operation

   Note: MySQL should be a semicolon after each command; the end.

Original: http: //blog.sina.com.cn/s/blog_87fad56a0101fv1f.html

Guess you like

Origin www.cnblogs.com/Ge-Zsj/p/12535986.html