Install MySQL under Linux

Source: Internet
Author: User

Install the compressed version of the *.tar.gz version of MySQL

1. 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

Setting a password for a MySQL user

[[email protected] Java EE] #passwd MySQL

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

2, extract the binary files to the specified installation directory, we specify here 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

3. 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.

4. 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=/usr/local/mysql--datadir=/usr/local/ 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

5. Copying configuration files

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

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

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

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

* Note the service name MySQL is the name we renamed when we copied Mysql.server to/etc/init.d/.

* See if Add success

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

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 MySQL

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 mysql start additional service MySQL stop service restart service MySQL restart

Execute under the bin directory of MySQL, or you have configured the environment variable to execute the following command directly to root user to set the password to root

[[email protected] bin]#./mysqladmin-u root password ' root '//Use this command to set the root account password to root

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:

Export Mysql_home=/usr/local/mysql

Export path= $MYSQL _home/bin: $PATH

Wq Save Exit VI

Executes the source./profile make the configuration environment variable effective

Give MySQL remote login permission

Grant all privileges on * * to ' root ' @ '% ' identified by ' root ' with GRANT option; Indicates that the MySQL service can be accessed through the root and root password on any remote address

Flush privileges; change takes effect

Install MySQL under Linux

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.