LNMP environment Configuration install MySQL database server

Source: Internet
Author: User
Tags flush


Nonsense not to say, although you can install MySQL directly through the Yum, but in order to be able to have a clearer understanding of the installation process, we still use the source code to compile the installation.

The code is as follows Copy Code

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
$ TAR-ZXVF mysql-5.6.21.tar.gz
$ CD mysql-5.6.21

The file has already been downloaded and unzipped, and we need to create a username and user group named MySQL for MySQL before we install it.

The code is as follows Copy Code
$ sudo groupadd MySQL
$ sudo useradd-r-g MySQL MySQL

After you have established the username and group, you are ready to compile and install the

The code is as follows Copy Code
$ cmake.
$ make
$ sudo make install

The compilation process is long and patient
If CMake is not installed, you need to first install

The code is as follows Copy Code
$ sudo yum install CMake
$ sudo yum install gcc-c++

If prompted

Warning:bison executable not found in PATH

You need to install Bison

$ sudo yum install Bison

If you receive the following error

--Could not find Curses (missing:curses_library curses_include_path)
CMake Error at cmake/readline.cmake:85 (message):
Curses Library not found. Please install appropriate package,

Remove CMakeCache.txt and rerun CMake. On Debian/ubuntu, package name are Libncurses5-dev, on Redhat and derivates it is ncurses-devel.

You need to install

$ sudo yum install Ncurses-devel

After a long compilation process, our MySQL finally installed to the/usr/local/mysql directory, next, we need to configure MySQL, so that MySQL becomes available.

The code is as follows Copy Code

$ cd/usr/local/mysql/
$ sudo chown-r MySQL.
$ sudo chgrp-r MySQL.
$ sudo scripts/mysql_install_db--user=mysql

The mysql_install_db script here only needs to be manually compiled to install MySQL, and the script creates an authorization table for MySQL.
Most MySQL installations are owned by the root user, but it must be guaranteed that the data directory is a MySQL user.

The code is as follows Copy Code
$ sudo chown-r root.
$ sudo chown-r mysql data

Finally, we need to create a MySQL configuration file

The code is as follows Copy Code
$ sudo cp support-files/my-default.cnf/etc/my.cnf

Configure MySQL Boot boot

If you want MySQL to start automatically when the system starts, you can execute the following command

The code is as follows Copy Code

$ sudo cp support-files/mysql.server/etc/init.d/mysql.server
$ sudo chmod u+x/etc/init.d/mysql.server
$ sudo chkconfig--add mysql.server

Perform chkconfig |grep MySQL see the following, especially if run Level 3 is enabled, the setting is successful.

$ chkconfig |grep MySQL
Mysql.server 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off

MySQL can be started and closed via the Mysql.server script.

$ sudo/etc/init.d/mysql.server [Start|stop]

If you want to manually operate, start MySQL using the command:

$ Sudo/usr/local/mysql/bin/mysqld_safe--user=mysql &

To turn off MySQL:

$./mysqladmin-u Root shutdown

Modify root account password

The root account for the newly installed MySQL database is not set to password, so everyone can access it, and for security reasons, we need to set a password for the root account.

The code is as follows Copy Code

$/usr/local/mysql/bin/mysql-uroot
Mysql> SELECT User, Host, Password from Mysql.user;
+------+-----------------------+----------+
| User | Host | Password |
+------+-----------------------+----------+
| Root |          localhost | |
| Root |          Localhost.localdomain | |
| Root |          127.0.0.1 | |
| Root |          :: 1 | |
| |          localhost | |
| |          Localhost.localdomain | |
+------+-----------------------+----------+
6 rows in Set (0.00 sec)

Here User A column is empty anonymous user information, use MySQL direct landing, without providing account number, will be the user's identity landing database, if you do not need the user, you can delete the user information.

The code is as follows Copy Code

mysql> DROP USER ' @ ' localhost ';
mysql> DROP USER ' @ ' localhost.localdomain ';

Usually we have three ways to set a password for a MySQL user:
The first way is to use the set PASSWORD, which we need to log in to MySQL.

The code is as follows Copy Code

mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' root ');
Query OK, 0 rows Affected (0.00 sec)

mysql> SET PASSWORD for ' root ' @ ' 127.0.0.1 ' = PASSWORD (' root ');
Query OK, 0 rows Affected (0.00 sec)

mysql> SET PASSWORD for ' root ':: 1 ' = PASSWORD (' root ');
Query OK, 0 rows Affected (0.00 sec)

The second way is more straightforward, using Updata to modify the datasheet directly.

The code is as follows Copy Code

mysql> UPDATE mysql.user SET Password = Password (' root ') WHERE user = ' root ';
Query OK, 1 row Affected (0.00 sec)
Rows Matched:4 changed:1 warnings:0

mysql> FLUSH privileges;
Query OK, 0 rows Affected (0.00 sec)

The flush statement here allows the database to reload the authorization table, otherwise it will not take effect until the next reboot.
The third way is to use the mysqladmin command, but this is not a way to change the password for ' root ' @ ' 127.0.0.1 ' and ' root ':: 1 '.

  code is as follows copy code

shell> mysqladmin-u root Password "newpwd"
shell> mysqladmin-u root-h host_name password "newpwd"

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.