Build MySQL database on Centos7

Source: Internet
Author: User

MySQL Service Basics:

MySQL is a true multi-threaded, multi-user SQL database service that has become the most popular open source database system in the server domain with its high performance, reliability, and ease of use.

MySQL Compilation installation:

1. Installing the Support software

yum install gcc gcc-c++ ncurses ncurses-devel cmake -y

2. Create a running user MySQL, and extract the MySQL source package to the/opt/directory, the boost source package to extract to the/usr/local/directory, the extracted boost package renamed Easy to manage.

useradd -s /sbin/nologin mysqltar zxvf mysql-5.7.17.tar.gz -C /opt/tar zxvf boost_1_59_0.tar.gz -C /usr/local/cd /usr/local/mv boost_1_59_0 boost

3. During the configuration process, you can set the default character set to UTF8 and add support for other character sets.

cd mysql-5.7.17/-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \       //安装目录//-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \  -DSYSCONFDIR=/etc \                            //指定初始化参数文件目录//-DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8  \                    //指定默认使用的字符集编码//-DDEFAULT_COLLATION=utf8_general_ci \       //适用于UTF-8字符集的通用规则//-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost \            //指定Boost库的位置,5.7版本必须添加这个参数-DWITH_SYSTEMD=1

------NOTE: If there is an error in the process of CMake, when the error is resolved, you need to remove the CMakeCache.txt file from the source directory, and then cmake again, otherwise the errors are still------------

4. Compiling and installing

make          make install

------Note: If during the make loading process, the memory of the virtual machine is set to 2G, then make compile//, if the error error occurs during the build process, The following methods can be solved: Download the mysql-boost-5.7 package and unzip it, and in the configuration, change the Boost function library location from-dwith_boost=/usr/local/boost \ to-dwith_boost=boost \

5. Set permissions on the directory of the database

chown -R mysql.mysql /usr/local/mysql/

6. Under the Support-files folder in the MySQL source directory, build the/ETC/MY.CNF configuration file for the MySQL system.

vi /etc/my.cnf[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

7. Modify the owner and/etc/my.cnf of the master configuration file

chown mysql:mysql /etc/my.cnf

8. Set environment variables, in order to facilitate the use of MySQL command in any directory, you need to set the environment variable in/etc/profile.

echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profileecho ‘export PATH‘ >> /etc/profilesource /etc/profile       //开启//

9. Initialize the database, in order to be able to use the MySQL database system, should be run user MySQL identity initialization, specify the data storage directory, and so on.

cd /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

10. Add MYSQLD system services for management through SYSTEMCTL, and you can use the service scripts provided in the source package directly. Locate the Mysql.server script file under the usr/lib/systemd/system/folder, copy it to the/usr/lib/systemd/directory, rename it to System, and then reload.

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/systemctl daemon-reload    //重新加载系统服务管理模块

11. Start the MYSQLD service and see if the TCP3306 port is turned on

systemctl start mysqldnetstat -anpt | grep 3306[[email protected] mysql]# netstat -anpt | grep 3306tcp6       0      0 :::3306                 :::*                    LISTEN      23765/mysqld        

12. Turn off the firewall

systemctl stop firewalld.service setenforce 0

13. Set the root login password for the database

mysqladmin -u root -p password "abc123"

14. Log in to the database

[[email protected] mysql]# mysql -u root -pEnter password:       Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.17 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘ with grant option;Query OK, 0 rows affected, 1 warning (0.00 sec)

15. View the database structure

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)

Build MySQL database on Centos7

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.