Two ways to install MySQL on Linux

Source: Internet
Author: User
Tags mysql client reserved

Reprint: http://blog.csdn.net/superchanon/article/details/8546254/

1. Operating platform: CentOS 6.3 x86_64, basically equivalent to Rhel 6.3

2. Installation Method:

There are two main ways to install MySQL: one is self-compiling through the source of the installation, this is suitable for advanced user custom MySQL features, not to do this, and the other is to install through the compiled binary files. Binary file installation methods are divided into two types: one is not for the specific platform of the common installation method, the use of the binary file is the suffix. tar.gz of the compressed file, the second is to use the RPM or other packages for installation, the installation process will automatically complete the configuration of the system, so it is more convenient.

3. Download the installation package:

A. Official:

http://dev.mysql.com/downloads/mysql/#downloads

or image file Download:

Http://dev.mysql.com/downloads/mirrors.html

2. Download the file (select the appropriate release version according to the operating system):

A. General installation method

Mysql-5.5.29-linux2.6-x86_64.tar.gz

B. RPM Installation Method:

mysql-server-5.5.29-2.el6.x86_64.rpm

mysql-client-5.5.29-2.el6.x86_64.rpm

4. General installation Steps

A. Check that the-I option for grep indicates that a match is ignored if it is installed

[[email protected] Java EE] #rpm-qa|grep-i MySQL

Mysql-libs-5.1.61-4.el6.x86_64

* You can see that the library file has been installed, should be uninstalled first, or there will be overwrite errors. Note unloading: The--nodeps option was used when loading, ignoring the dependency relationship:

[email protected] Java EE] #rpm-e mysql-libs-5.1.61-4.el6.x86_64--nodeps

B. Add MySQL group and MySQL user to set the MySQL installation directory file owner and owning group.

[[email protected] Java EE] #groupadd MySQL

[[email protected] Java EE] #useradd-r-G MySQL MySQL

The *useradd-r parameter indicates that the MySQL user is a system user and cannot be used to log on to the system.

C. Extract the binaries to the specified installation directory, which we specify as/usr/local

[Email protected] ~]# cd/usr/local/

[[email protected] local] #tar zxvf/path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

* After pressurization in/usr/local/generate understand the pressure after the folder mysql-5.5.29-linux2.6-x86_64, this name is too long, we create a symbolic link for it mysql, convenient input.

[[email protected] local] #ln-s mysql-5.5.29-linux2.6-x86_64 MySQL

D. Directory structure under/usr/local/mysql/

Directory

Contents of Directory

Bin

Client programs and the mysqld server

Data

Log files, databases

Docs

Manual in Info format

Mans

Unix manual Pages

Include

Include (header) files

Lib

Libraries

Scripts

mysql_install_db

Share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

Sql-bench

Benchmarks

E. Go to the MySQL folder, which is the directory where MySQL resides, and change the group and user to which it belongs.

[[email protected] local] #cd MySQL

[[email protected] MySQL] #chown-r MySQL.

[[email protected] MySQL] #chgrp-r MySQL.

F. Execute the mysql_install_db script to initialize the data directory in MySQL and create some system tables. Note that the MySQL service process mysqld accesses the data directory, so it must be executed by the user who started the mysqld process (the MySQL user we set up earlier), or by root, but with the parameter--user=mysql.

[Email protected] mysql]scripts/mysql_install_db--user=mysql

* If the MySQL installation directory (extract directory) is not/usr/local/mysql, then you must also specify the directory parameters, such as

[Email protected] mysql]scripts/mysql_install_db--user=mysql \

--basedir=/opt/mysql/mysql \

--datadir=/opt/mysql/mysql/data

* All files in the mysql/directory except the data/directory are changed back to the root user, and the MySQL user only needs to be the owner of all files in the mysql/data/directory.

[[email protected] mysql]chown-r root.

[[email protected] mysql]chown-r MySQL data

G. Copying a configuration file

[[email protected] MySQL] CP support-files/my-medium.cnf/etc/my.cnf

H. Add the Mysqld service to the boot entry.

* First, you need to copy the Scripts/mysql.server service script to/etc/init.d/and rename it to Mysqld.

[[email protected]] CP support-files/mysql.server/etc/init.d/mysqld

* The MYSQLD service is added to the self-starting service item via the Chkconfig command.

[[email protected] MySQL] #chkconfig--add mysqld

* Note Service name Mysqld is the name that we renamed when we copied Mysql.server to/etc/init.d/.

* See if Add success

[[email protected] MySQL] #chkconfig--list mysqld

Mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

I. Restart the system and the mysqld will start automatically.

* Check whether to start

[[email protected] MySQL] #netstat-anp|grep mysqld

TCP 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld

UNIX 2 [ACC] STREAM LISTENING 14396 2365/mysqld/tmp/mysql.sock

* If you do not want to reboot, you can start it manually.

[[email protected] MySQL] #service mysqld start

Starting MySQL. success!

J. Run the client program MySQL, and in the Mysql/bin directory, test whether you can connect to mysqld.

[Email protected] Mysql]#/usr/local/mysql/bin/mysql

Welcome to the Mysqlmonitor. Commands End With; or \g.

Your MySQL Connection Idis 2

Server Version:5.5.29-log MySQL Community Server (GPL)

Copyright (c), 2012,oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of the Oracle Corporation and/or its affiliates. Other names Betrademarks of their respective owners.

Type ' help; ' or ' \h ' forhelp. Type ' \c ' to clear the current input statement.

Mysql> quit

Bye

* The mysql> command prompt appears, you can enter the SQL statement, enter quit or exit. To avoid entering MySQL's full path/usr/local/mysql/bin/mysql each time, add it to the environment variable, and then add two lines of command to the/etc/profile:

Mysql_home=/usr/local/mysql

Export path= $PATH: $MYSQL _home/bin

This allows you to start the client program by entering the MySQL command directly in the shell.

[[email protected] MySQL] #mysql

Welcome to the Mysqlmonitor. Commands End With; or \g.

Your MySQL Connection Idis 3

Server Version:5.5.29-log MySQL Community Server (GPL)

Copyright (c), 2012,oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of the Oracle Corporation and/or its

Affiliates. Other Namesmay is trademarks of their respective

Owners.

Type ' help; ' or ' \h ' forhelp. Type ' \c ' to clear the current input statement.

Mysql>

5. RPM Installation Steps

A. Check that the-I option for grep indicates that a match is ignored if it is installed

[[email protected] Java EE] #rpm-qa|grep-i MySQL

Mysql-libs-5.1.61-4.el6.x86_64

It can be seen that the library files have been installed, should be uninstalled first, or there will be overwrite errors. Note The--nodeps option is used when uninstalling, ignoring dependencies:

[email protected] Java EE] #rpm-e mysql-libs-5.1.61-4.el6.x86_64--nodeps

2. Install the MySQL server-side software, and note the switch to the root user:

[[email protected] Java EE] #rpm-ivh mysql-server-5.5.29-2.el6.x86_64.rpm

When the installation is complete, the installation process adds a MySQL group to Linux and MySQL for users who belong to the MySQL group. Can be viewed by the ID command:

[[email protected] Java EE] #id MySQL

uid=496 (MySQL) gid=493 (MySQL) groups=493 (MySQL)

MySQL server after installation, although the relevant files are configured, but does not automatically start the MYSQLD service, you need to start it yourself:

[[email protected] Java EE] #service mysql start

Starting MySQL. success!

Check to see if MySQL is booting properly by checking that the port is turned on:

[[email protected] Java EE] #netstat-anp|grep 3306

TCP 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld

C. Install the MySQL client software:

[[email protected] Java EE] #rpm-ivh mysql-client-5.5.29-2.el6.x86_64.rpm

If the installation is successful, you should be able to run the MySQL command, note that the MYSQLD service must be enabled:

[[email protected] Java EE] #mysql

Welcome to the Mysqlmonitor. Commands End With; or \g.

Your MySQL Connection Idis 1

Server Version:5.5.29mysql Community Server (GPL)

Copyright (c), 2012,oracle and/or its affiliates. All rights reserved.

Oracle is a registered TRADEMARKOF Oracle Corporation and/or its affiliates. Names may trademarks Oftheir respective owners.

Type ' help; ' or ' \h ' forhelp. Type ' \c ' to clear the current input statement.

Mysql>

D. RPM installation file distribution

Directory

Contents of Directory

/usr/bin

Client Programs and Scripts

/usr/sbin

The mysqld server

/var/lib/mysql

Log files, databases

/usr/share/info

Manual in Info format

/usr/share/man

Unix manual Pages

/usr/include/mysql

Include (header) files

/usr/lib/mysql

Libraries

/usr/share/mysql

Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database I Nstallation

/usr/share/sql-bench

Benchmarks

Two ways to install MySQL on Linux

Related Article

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.