(5) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Mysql Installation

Source: Internet
Author: User
Tags mysql update

(5) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Mysql Installation

 

In my local testing practice, the following is a complete operating document for Centos + Nginx + Tomcat + Mysql on Linux. The record is as follows, we hope to give a systematic reference to programmers who want to build a Linux environment systematically. However, because most of the operations are recorded while being built, some omissions are inevitable. I still hope you will forgive me. If you have any questions or comments, please help me to point them out in the comments below. Thank you very much! In addition, many excellent practices on the Internet have been referenced during the entire construction process. They are marked at the end of the article or in other appropriate places. If necessary, you can refer to the reference link to read the reference Original article. This document consists of six parts and six articles:

1. (1) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-FTP Installation

2. (2) deploying the Linux environment (Centos + Nginx + Tomcat + Mysql)-firewall configuration

3. (3) deployment of the Linux environment (Centos + Nginx + Tomcat + Mysql)-deployment of the Nginx Environment

4. (4) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-install Tomcat and JDK and integrate Nginx with Tomcat

5. (5) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Mysql Installation

6. (6) Linux environment deployment (Centos + Nginx + Tomcat + Mysql)-Summary of some common commands

(5) install Mysql

 

1. Check whether the installation has been installed:

Yumlist installed mysql *

Rpm-qa | grep mysql *

Check whether the installation package is available:

Yum list mysql *

Install the mysql client:

Yum install mysql

Install the mysql server:

Yum install mysql-server yum

Install mysql-devel

2. Start & stop database character set settings

Add default-character-set = utf8 to the mysql configuration file/etc/my. cnf.

Start mysql service: servicemysqld start or/etc/init. d/mysqld start

Start startup:

Add boot start: chkconfig -- add mysqld;

Start: chkconfig mysqld on;

Check whether the boot setting is successful. chkconfig -- list | grep mysql * mysqld 0: off 1: off 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable stop:

Service mysqld stop

3. log on to create a root administrator:

Mysqladmin-u root password 123456

Log on to mysql-u root-p and enter the password. Forgot password: service mysqld stop mysqld_safe -- user = root -- skip-grant-tables mysql-u root use mysql update user setpassword = password ("new_pass") where user = "root "; flushprivileges;

4. remote access to the port number of the open firewall mysql

Add permission: the user table in the mysql database adds a record with host as "%" and user as "root ".

5. Important directories of Linux MySQL

Database directory/var/lib/mysql/

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

Related commands/usr/bin (commands such as mysqladminmysqldump)

Start script/etc/rc. d/init. d/(start script file mysql directory)

 

6. delete a mysql database

If you want to delete mysql installed in yum, run the following command:

Yum-y remove mysql *

Delete all files in the/var/lib/mysql folder.

Then re-execute the above installation steps.

 

7. Authorize the user to log on remotely

1. Change the table. It may be that your account is not allowed to log on remotely, but only on localhost. At this time, you only need to log in to mysql on the computer of localhost, and change the "host" entry in the "user" table in the "mysql" database to "%" from "localhost"

Mysql-u root-pvmwaremysql> usemysql; mysql> update user set host = '%' where user = 'root'; mysql> selecthost, user from user;

2. Authorization method. For example, if you want myuser to use mypassword to connect to the mysql server from any host.

Grant all privileges on *. * TO 'myuser' @ '%' identified by 'mypassword' with grant option;

If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.3, and use mypassword as the password

Grant all privileges on *. * TO 'myuser' @ '192. 168.1.3 'identified BY 'mypassword' with grant option;

 

 

Modify the default storage location of Mysql database data

Reference: http://www.jb51.net/article/33578.htm

 

Because the MySQL database is too large, the default/var disk can no longer accommodate new data. There is no way to transfer the data directory. I am attaching an external data disk to/data in/data.

Next, I will sort out the specific operations to transfer MySQL from the/var/lib/mysql directory to the/data/mysql directory:

 

Check the storage path of the current data file in the database:

Mysql> show variables like '% dir % ';



1. First, we need to disable MySQL. The command is as follows::
Service mysqld stop
2. Transfer DataFor the sake of security, we use the copy command cp to first find the original directory of mysql
Cd/var/lib
Ls
After running this command, you will see the mysql directory and then execute the cp command
Cp-a mysql/data/# copy the database to/dat.

Note:(-A must be taken with this parameter; otherwise, the permission for copying is incorrect .)

If the database is large, it will take a long time and may time out. For more information about how to set the ssh timeout mode, please contact us.
3. modify the configuration file. There are three configuration files. I will describe them one by one.:
Modify the first file: Back up cp/etc/my. cnf/etc/my. cnfbak before modification
Vi/etc/my. cnf
After the datadir directory is opened, change it to/data/mysql.
Change the socket to/data/mysql. sock # To ensure security, you can comment out the original one and add a new line to the current directory.
Modify the second file: before modification, back up cp/etc/init. d/mysqld/etc/init. d/mysqldbak
Vi/etc/init. d/mysqld
Note: The exact location is/etc/rc. d/init. d/mysqld, because here there is a/etc/init. d to/etc/rc. d/init. d ing,
Therefore, it is easy to use the preceding command.
Change the path on the Right of datadir =/var/lib/mysql to your actual storage path:/data/mysql
Modify the third file: Back up cp/usr/bin/mysqld_safe/usr/bin/mysqld_safebak
Vi/usr/bin/mysqld_safe
The directory for modifying datadir is/data/mysql.
4. Create a mysql. sock link below.:
Ln-s/data/mysql. sock/var/lib/mysql. sock

Now all the modifications have been completed. Start mysql
Service mysqld start
Or restart linux.
Reboot
If it can be started properly, the modification is successful.

 

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.