Install MySQL under Linux

Source: Internet
Author: User
Tags administrator password

Suppose you put all the necessary source code or packages in the/TMP. If you're downloading a RPM package, it's easier, and if you're downloading a binary package (you don't have an RPM program or you want to customize it), it's a bit trickier.

RPM Package Installation

You must be a root user to use the RPM installer, the following are the installation procedures:

$ cd/tmp
$ su
# RPM-UVH mysql* (Install all MySQL-related packages)

This will install all 3 MySQL packages you downloaded. If your system is Redhat Linux, it is recommended to use RPM installation, because all the work is done by the RPM program to help you.

Source Installation

Compared with the RPM installation, the binary source installation is a little more trouble. However, we can customize the installation parameters in the installation script, instead of installing the default only if the RPM method is installed.

Installing binary source code

If you download binary source code, its name is similar to: mysql-3.22.21-pc-linux-gnu-i686.tar.gz. You must be the root user and then extract to the/usr/local directory with the following steps:

$ cd/usr/local
$ su
# tar-zxvf/tmp/mysql-3.22.21-pc-linux-gnu-i686.tar.gz

After all the files have been extracted, a directory named mysql-3.22.21-pc-linux-gnu-i686 will be created. Let's make a symbolic link to this directory and give it a more friendly name for MySQL (lest it be called mysql-3.22.21-pc-linux-gnu-i686 so long):

# ln-s mysql-3.22.21-pc-linux-gnu-i686 MySQL

If there is a new version of MySQL later, you can just extract the source code to the new path, and then only need to make a symbolic link. This is very convenient and the data is more secure.

 

build a MySQL user

OK, now we will create a user account that can run the MySQL daemon, and all MySQL files are owned by this account. Use the linuxconf or Useradd command to add an account called MySQL, before adding, make sure that no one has registered the account, but also temporarily prohibit the login function (but generally in the absence of other people logged in the case of debugging machines, so this step is free)

 

preparing for MySQL

First let's change the ownership of the MySQL directory and files to the MySQL user and root group:

# cd/usr/local
# chown-r Mysql:root mysql-3.22.21-pc-linux-gnu-i686 MySQL

Then run a small script program to build the initialized MySQL database. Please complete this task as a MySQL user, which is the only opportunity for us to use this account directly.

# su MySQL
$ cd MySQL
$ scripts/mysql_install_db
$ exit

If there is no error message to display, then it's okay.

 

run MySQL automatically

Inside the MySQL binary package, there is a startup script called Myslq.server. Copy it to the/ETC/RC.D/INIT.D directory:

# CD/ETC/RC.D/INIT.D
# cp/usr/local/mysql/support-files/mysql.server MySQL

Then change its properties to "X" (Executable, executable)

# chmod +x MySQL

Finally, run chkconfig to add MySQL to your system's startup service group.

#/sbin/chkconfig--del MySQL
#/sbin/chkconfig--add MySQL

 

test MySQL

MySQL has a simple database example test, and its internal database keeps monitoring permissions and accounts, so run MySQL first to see if it works.

Start MySQL First:

#/etc/rc.d/init.d/mysql Start

If everything is OK, you will see the following information appear:

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

If you install the RPM package, then the program is mostly installed in/usr/local/mysql/bin. Run the client program in this directory:

# MySQL

You can then see the following information displayed on the screen:

Welcome to the MySQL Monitor. Commands End With; Or/g.

Your MySQL Connection ID is 2 to server version:3.22.21

Type ' help ' for help.

Mysql>

Next, you can list the installed database with the show databases command:

mysql> show databases;

You can see:

+----------+

| Database |

+----------+

| MySQL |

| Test |

+----------+

2 rows in Set (0.00 sec)

If everything works, it means that MySQL can work completely! congratulations! If you want to exit the program, enter: Exit

Mysql> exit;

Bye

Change the administrator password

After everything is OK, the first thing to do is change the administrator's password. You can run Mysqladmin (note that this command is not necessarily in your path, so it is best to go directly to the directory where this command is executed):

# mysqladmin-u Root Password NewPassword

This command turns the root user's password into newpassword. Of course you can change the password to something else, because it's easy to crack.

Install MySQL under 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.