How to install MySQL database on Linux operating system

Source: Internet
Author: User
Tags mysql in socket mysql database

1, download the MySQL installation files

The following two files are required to install MySQL:

mysql-server-5.0.26-0.i386.rpm

mysql-client-5.0.26-0.i386.rpm

Download Address: http://dev.mysql.com/downloads/mysql/5.0.html, open this page, Drop-down page to find "Red Hat Enterprise Linux 3 RPM (x86) downloads", find " Server "and" Client programs "items, download the required two RPM files.

2, install MySQL

The rpm file is a software installation package developed by Red Hat, which allows Linux to remove many complex procedures when installing software packages. The commonly used parameter for this command at installation is –IVH, where I indicates that the specified RMP package will be installed, V represents details of the installation, and H indicates that the "#" symbol appears during installation to display the current installation process. This symbol will continue until the installation is complete before stopping.

1) Install server side

Run the following command in a directory with two RMP files:

[Root@test1 local]# RPM-IVH mysql-server-5.0.26-0.i386.rpm

Displays the following information.

Warning:mysql-server-5.0.26-0.i386.rpm:v3 DSA Signature:nokey, key ID 5072e1f5

preparing...########################################### [100%]

1:mysql-server########################################### [100%]

。。。。。。 (Omitted display)

/usr/bin/mysqladmin-u root password ' new-password '

/usr/bin/mysqladmin-u root-h test1 password ' new-password '

。。。。。。 (Omitted display)

Starting mysqld daemon with databases From/var/lib/mysql

If appear as above information, the service side installs completes. Test whether the success can be run netstat see whether the MySQL port is turned on, such as open means that the service has been started, the installation was successful. The default port for MySQL is 3306.

[Root@test1 local]# Netstat-nat

Active Internet connections (servers and established)

Proto recv-q send-q Local addressforeign addressstate

Tcp00 0.0.0.0:33060.0.0.0:*listen

The above shows that the MySQL service has been started.

2) Install the client

Run the following command:

[Root@test1 local]# RPM-IVH mysql-client-5.0.26-0.i386.rpm

Warning:mysql-client-5.0.26-0.i386.rpm:v3 DSA Signature:nokey, key ID 5072e1f5

preparing...########################################### [100%]

1:mysql-client########################################### [100%]

Show installation complete.

Connect MySQL with the following command to test for success.

Login to MySQL

The command to log in to MySQL is MySQL, and the usage syntax for MySQL 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 a Linux system

User. MySQL Default user is root, because the initial no password, the first time to enter a MySQL can only.

[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>

There is a "mysql>" prompt, congratulations, installation success!

The login format with the password added is as follows:

Mysql-u root-p

Enter Password: (enter password)

Where-U is followed by the username,-p requires a password, enter the password at the input password.

Note: This MySQL file is in the/usr/bin directory and is not a file/etc/init.d/mysql the startup file that follows.

Several important directories of MySQL

MySQL installation is complete unlike SQL Server default installed in a directory, its database files, configuration files and command files in different directories, understand these directories are very heavy

To, especially for Linux beginners, because Linux itself is more complex directory structure, if not clear MySQL installation directory that can not talk about in-depth study.

Here are some of these directories.

1. Database Directory

/var/lib/mysql/

2. Configuration file

/usr/share/mysql (mysql.server command and configuration file)

3. Related Orders

/usr/bin (mysqladmin mysqldump order)

4. Startup script

/etc/rc.d/init.d/(Directory of startup script files MySQL)

Modify login Password Total 2 pages.

MySQL defaults to no password, the importance of installing the password added is self-evident.

1. Order

usr/bin/mysqladmin-u root password ' new-password '

Format: Mysqladmin-u username-P Old password password new password

2. Examples

Example 1: Add a password of 123456 to root.

Type the following command:

[Root@test1 local]#/usr/bin/mysqladmin-u root password 123456

Note: Since Root does not have a password at the beginning, the-p old password can be omitted.

3. Test whether the modification is successful

1 Login without password

[Root@test1 local]# MySQL

ERROR 1045:access denied for user: ' Root@localhost ' (Using password:no)

An error is displayed, indicating that the password has been modified.

2 Login with modified password

[Root@test1 local]# mysql-u root-p

Enter Password: (enter 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 through the mysqladmin command to modify the password, or you can change the password by modifying the library.

Start and stop

1, start

MySQL installation is completed after the boot file MySQL in the/ETC/INIT.D directory, when you need to start running the following command.

[Root@test1 init.d]#/etc/init.d/mysql start

2. Stop

/usr/bin/mysqladmin-u root-p shutdown

3, automatic start

1 See if MySQL is in the auto start list

[Root@test1 local]#/sbin/chkconfig–list

2 Add MySQL to your system's startup service group

[Root@test1 local]#/sbin/chkconfig–add MySQL

3 Remove MySQL from the Startup service group.

[Root@test1 local]#/sbin/chkconfig–del MySQL

Change MySQL Directory

MySQL defaults to the data file storage directory for/var/lib/mysql. The following steps are required if you want to move the directory to/home/data:

1, the home directory to establish the data directory

Cd/home

mkdir data

2, the MySQL service process to stop:

Mysqladmin-u root-p shutdown

3. Move/var/lib/mysql Entire directory to/home/data

mv/var/lib/mysql/home/data/

This will be the MySQL data file moved to the/home/data/mysql

4, find my.cnf configuration file

If there is no MY.CNF configuration file in the/etc/directory, please find *.cnf file under/usr/share/mysql/, copy one to/etc/and rename to my.cnf). The order is as follows:

[Root@test1 mysql]# cp/usr/share/mysql/my-medium.cnf/etc/my.cnf

5, edit the MySQL configuration file/etc/my.cnf

To ensure that MySQL works properly, you need to indicate where the Mysql.sock file will be generated. Modify the value on the right side of the equal sign in a Socket=/var/lib/mysql/mysql.sock row

As:/home/mysql/mysql.sock. The operation is as follows:

VIMY.CNF (use VI tool to edit MY.CNF file, find the following data modification)

# The MySQL server

[Mysqld]

Port= 3306

#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" comment on this row)

socket=/home/data/mysql/mysql.sock (plus this trip)

6, modify the MySQL startup script/etc/rc.d/init.d/mysql

Finally, you need to modify the MySQL startup script/etc/rc.d/init.d/mysql, put the path to the right of the equal sign in the Datadir=/var/lib/mysql line, and change it to the actual save

Put path: Home/data/mysql.

[Root@test1 etc]# Vi/etc/rc.d/init.d/mysql

#datadir =/var/lib/mysql (note this row)

Datadir=/home/data/mysql (plus this row)

7, restart the MySQL service

/etc/rc.d/init.d/mysql start

or restart Linux with the reboot command

If the work is moving normally, it will be successful, otherwise check the previous 7 steps.

In order to be able to log on to another computer with the root user, the following actions are required:

1, mark@marklinux mark>mysql-h localhost-u root

This should allow access to the MySQL server

2, mysql>grant all privileges in *.* to ' root ' @ '% ' with GRANT OPTION

Give any host access to data

3, Mysql>flush privileges

Change takes effect

4, Mysql>exit

Exit MySQL Server

This allows you to log in as root on any other host!

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.