Set up MySQL in Linux and MySQL in Linux

Source: Internet
Author: User

Set up MySQL in Linux and MySQL in Linux

1. before installing the mysql database server, make sure that your linux system can connect to the network. We will install mysql through the source code, first, make sure that the gcc c ++ and other compiling environments have been installed in the system, because mysql has been compiled using cmake since Version 5.5. If none of the three environments are installed, you can run the following command to install the SDK:

Yum-y install make gcc-c ++ cmake bison-devel ncurses-devel

2. Check whether the mysql database components have been installed in the system. Run the command: rpm-qa | grep mysql.

If you find it, use the following command to force uninstall: rpm-e -- nodeps package name

3. Download the mysql source code installation package under the user directory of the current login user (press the cd key ).

Command: wget -- no-check-certificate https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz (no -- no-check-certificate command will report an error)

 

4. After the download is complete, run the command: ls to view the current mysql-5.6.24.tar.gz

 

5. Unzip, command: tar-zxvf mysql-5.6.24.tar.gz or tar-zxf mysql-5.6.24.tar.gz (-zxvf can see the decompression process,-zxf omitted to understand the pressure process)

6. Jump to the extracted mysql directory, command: cd mysql-5.6.24

7. Start to compile the mysql file. First configure the compilation parameters.

Command: cmake \-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \-DMYSQL_DATADIR =/usr/local/mysql/data \-DSYSCONFDIR =/etc \-region = 1 \-DWITH_INNOBASE_STORAGE_ENGINE = 1 \ -DWITH_MEMORY_STORAGE_ENGINE = 1 \-DWITH_READLINE = 1 \-DMYSQL_UNIX_ADDR =/var/lib/mysql. sock \-DMYSQL_TCP_PORT = 3306 \-DENABLED_LOCAL_INFILE = 1 \-character = 1 \-DEXTRA_CHARSETS = all \-DDEFAULT_CHARSET = utf8 \-DDEFAULT_COLLATION = utf8_general_ci

8. Use make & make install to compile and install mysql.

9. After the installation is complete, we need to configure mysql. First, set the mysql access permission and run the command to check whether mysql users and user groups already exist.

Jump to the user directory: cd ~

Command for viewing user list: cat/etc/passwd

Command for viewing user group list: cat/etc/group

10. If it does not exist, we will create:

Add User Group command: groupadd mysql

Add User: useradd-g mysql

Then modify the user and user group accessing the directory where the previously installed mysql is located and enter the command: chown-R mysql: mysql/usr/local/mysql

11. Then initialize the mysql configuration.

Switch to the mysql installation directory: cd/usr/local/mysql

Run the initialization configuration script to create the mysql Built-in System Database :. /scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- user = mysql

Note: errors may occur in this area.

After you enter the./scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- user = mysql command

The above error occurs. cause: the host name cannot be resolved! Note that the content in the red box is the host name you modified when creating linux. The default host name is localhost. localdomain. Of course, this error will not occur if you did not change the default host name when setting up linux.

Solution: vim/etc/hosts then adds the host name in the red box to the end of each line, as shown in figure

 

After completing the configuration, execute the command again./scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- user = mysql

12. Modify the mysql configuration file

Run vi my. cnf.

Add the following content to the file: basedir =/usr/local/mysql

Datadir =/usr/local/mysql/data

Port = 3306

Server_id = 1

Socket =/var/lib/mysql. sock

 

This step is very important. You need to change the owner of the configuration file: chown-R mysql: mysql/usr/local/mysql/my. cnf; otherwise, an error will be reported when the mysql service is started below;

Note: when starting the MySQL service, I will search for my in certain order. cnf is first found in the/etc directory. If it cannot be found, it will be found in the mysql directory you installed. In this example, It is/usr/local/mysql/my. cnf. Note: After the minimal installation of CentOS 6.4 is completed, a my. cnf, You need to rename this file to another name, such as:/etc/my. cnf. bak. Otherwise, the file will interfere with the correct configuration of MySQL installed by source code, resulting in startup failure. The command for renaming is mv my. cnf my. cnf. bak.

13. Add mysql to the startup Item and start the mysql service.

Cp support-files/mysql. server/etc/init. d/mysqld # copy the script

Chmod + x/etc/init. d/mysqld # Add executable permissions

Chkconfig -- add mysqld # add to sysV Service

Chkconfig mysqld on # auto start upon startup

Service mysqld start # start the mysql service

Netstat-aux | grep mysq # view the started mysql process

Note:

Service mysqld start # If the following error is reported when mysql service is started:

Starting MySQL... The server quit without updating PID file [failed] local/mysql/data/localhost. learn. pid ).

One solution:

At this point: ps-ef | grep mysql check whether the mysql process already exists in the process

If a process exists, use the kill-9 process number (number at the second position)

ThenService mysqld startStart mysql

Other methods (not tried ):

1. It may be that the/usr/local/mysql/data/guoqing. pid file has no write permission.

Solution: grant permissions and run "chown-R mysql: mysql "./Usr/local/mysql/data"" Chmod-R 755/usr/local/mysql/data "and restart mysqld!

2. mysql may be installed on the machine for the second time, and the Service Startup may be affected due to residual data.
Solution: Go to the mysql data DIRECTORY data to see, if there is a mysql-bin.index, just remove it, it is the culprit.

3. mysql uses/etc/my when the configuration file is not specified at startup. cnf configuration file. Open this file to check whether the data directory (datadir) is specified in [mysqld ).
Solution: Set this line in [mysqld]: datadir =/usr/local/mysql/data

4. skip-federated Field Problems
Solution: Check whether the skip-federated field has been commented out in the/etc/my. cnf file. If so, comment out the field immediately.

5. The error log directory does not exist.
Solution: use the "chown" "chmod" command to grant the mysql owner and permissions.

6. selinux. If it is a centos system, selinux is enabled by default.
Solution: Close it, open/etc/selinux/config, change SELINUX = enforcing to SELINUX = disabled, and then save the disk and restart the machine.

14. Add mysql environment variables to facilitate subsequent operations and passwords

Command: vi/etc/profile

Add the following content at the bottom of the file: PATH =/usr/local/mysql/bin: $ PATH

Export PATH

Save and exit

Enter the command to make the configuration take effect immediately: source/etc/profile

15. After installing mysql, the default root account is empty. Let's change the password and enter the command:Mysql-urootPress enter and enter the following command:Set password = PASSWORD ('20140901 ');After setting, enter the command quit to exit the mysql environment;

 

16. after setting the mysql password, you must enter the following command to log on to mysql correctly: Enter the command: mysql-uroot-p and press Enter. The system will prompt you to enter the password, the prompt line starting with mysql> is displayed. Here you can enter any valid SQL query statement, for example, show databases; to display all databases, note that the semicolons that follow a line cannot be lost. It identifies the end of a line of commands. Congratulations! mysql has been installed successfully.

 

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.