CentOS 7 compilation installs MySQL and adds MySQL to system service

Source: Internet
Author: User
Tags check character mkdir install perl

Install the dependency package first to avoid problems during the installation process

[[email protected] liuzhen]# yum-y install gcc gcc-c++[[email protected] liuzhen]# yum-y install Cmake[[email protected] liuzhen]# yum-y install Ncurses-devel[[email protected] liuzhen]# yum-y install autoconf[[email protected] liuzhen]# Yu M-y Install Perl Perl-devel

The above dependency package installation can also be done in one line

[Email protected] liuzhen]# yum-y install gcc gcc-c++ cmake ncurses-devel autoconf perl perl-devel

MySQL Source: https://dev.mysql.com/downloads/mysql/5.6.html#downloads

SOURCE Package Address: https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz

Create MySQL installation directory and data storage directory

[Email protected] liuzhen]# mkdir/usr/local/mysql[[email protected] liuzhen]# Mkdir/usr/local/mysql/data

mkdir Creating a Folder

-M: Set access permissions on the new directory

-P: If some directories in the path do not already exist, the system will automatically set up those directories that do not already exist.

Create a user, user group

[[email protected] liuzhen]# groupadd mysql[[email protected] liuzhen]# useradd-r-g MySQL MySQL

The Useradd command is used to establish the user account and create the user's starting directory, which is the ultimate user. New User password is empty

-G: Specifies the starting group to which the user belongs.

-D: Specifies the start directory at which the user logged in.

-S: Specifies the shell to use when the user is logged in. -s/sbin/nologin is not allowed to login shell

-G After the first MySQL is the group name, the second MySQL is the new user name, the new user information can be found in the/etc/passwd file

Unzip the file to the current folder

Tar backup, compression and decompression, Linux command, also a tool

-Z: Indicates that the TAR package is compressed by gzip, so the decompression needs to use Gunzip decompression

-X: Extract the files from the tar package

-V: Show more information

-F xxx.tar.gz: Specifies that the file being processed is xxx.tar.gz

tar.gz with tar zxvf decompression, tar.bz2 with tar jxvf decompression

Start installation

[Code] [[email protected] liuzhen]# TAR-ZXVF mysql-5.6.35.tar.gz[[email protected] liuzhen]# CD Mysql-5.6.35[[email protected] mysql-5.6.35]# CMake. -dcmake_install_prefix=/usr/local/mysql-dinstall_datadir=/usr/local/mysql/data-ddefault_charset=utf8-ddefault_ Collation=utf8_general_ci-dextra_charsets=all-denabled_local_infile=1[[email protected] mysql-5.6.35]# make & & Make Install

CMake parameter Description:

-dcmake_install_prefix=/usr/local/mysql//default installation directory

-dinstall_datadir=/usr/local/mysql/data//Database storage directory

-ddefault_charset=utf8//using UTF8 characters

-DDEFAULT_COLLATION=UTF8_GENERAL_CI//Check character

-dextra_charsets=all//Install all extended character sets

-denabled_local_infile=1//Allow import of data from local

-dmysql_user=mysql

-dmysql_tcp_port=3306

CMake detailed configuration Please refer to the MySQL website

Precautions:

If the installation fails to recompile, you need to clear the old object file and cache information.

[[email protected] mysql-5.6.35]# make Clean[[email protected] mysql-5.6.35]# rm-f cmakecache.txt[[email protected] mysq l-5.6.35]# rm-rf/etc/my.cnf

Set directory Permissions

[Email protected] liuzhen]# cd/usr/local/mysql[[email protected] mysql]# chown-r mysql:mysql. [Email protected] mysql]# chown-r mysql:mysql data

The chown command changes a file or directory's owner and owner group.

-R: Recursively alters the owner of the specified directory and all subdirectories and files under it.

-V: Displays the work done by the Chown command.

To add the MySQL startup service to the system service

[[email protected] liuzhen]# Cd/usr/local/mysql[[email protected] mysql]# CP support-files/my-default.cnf/etc/my.cnf

To create the underlying table:

[Email protected] liuzhen]# cd/usr/local/mysql[[email protected] mysql]#  ./scripts/mysql_install_db--user= Mysql

Configuring Environment variables

[Email protected] liuzhen]# Vi/etc/profile

Add the following two values at the bottom of the

Export Mysql_home= "/usr/local/mysql"

Export path= "$PATH: $MYSQL _home/bin"

and then save

Make the modified profile effective immediately

[Email protected] liuzhen]# Source/etc/profile

Add MySQL to the folder that controls the startup service and name MySQL, which is the service-controllable name, to start MySQL with the service MySQL start control

/ETC/INIT.D is a link to/etc/rc.d/init.d, adding a file in/ETC/INIT.D will synchronize to add an identical file under/ETC/RC.D/INIT.D

[[email protected] liuzhen]# Cd/usr/local/mysql/[[email protected] mysql]# CP support-files/mysql.server/etc/init.d/ Mysql

The Chkconfig command is primarily used to update (start or stop) and query run-level information for system services. Remember that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection

--add: Adds the specified system service, allows the chkconfig instruction to manage it, and simultaneously adds the relevant data to the system-initiated narrative file. Service scripts must be stored in the/etc/ini.d/directory

To add the MySQL service to the list of services that are managed by the boot command

[[email protected] liuzhen]# chkconfig--add MySQL

Boot from MySQL service

On: For the service has a level limit, specific query chkconfig detailed

[[email protected] liuzhen]# chkconfig MySQL on

You can now start MySQL using the following command

[[Email protected] liuzhen]# service MySQL start

Stop MySQL Service

[[Email protected] liuzhen]# service MySQL stop

Restart MySQL Service

[[Email protected] liuzhen]# service MySQL restart

The following two commands work the same way

Systemctl [Stop|start|restart] Service Name

Service name [Stop|start|restart]

Enter to set a new password in the next prompt

[Email protected] liuzhen]# mysqladmin-u root passwordnew password:confirm new password: [[email protected] liuzhen]#

Connect to MySQL

[Email protected] mysql]#   

Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server version:5.6.35 Source Distribution

Copyright (c), Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

The ability to add remote connections for root

Mysql>Use mysql;mysql>desc User;mysql> GRANT All privileges on * * to Root@"%"Identified by"Root";//the ability to add remote connections for root. Mysql>update UserSetPassword = Password ('xxxxxx')whereUser='Root'; MySQL>SelectHost,user,password fromUserwhereUser='Root'; MySQL>flush privileges;//Refresh PermissionsMysql>exit//Exit

The remaining four grant examples

Assign the user User1 from 192.168.155.1 the ability to perform operations such as Select,insert,update,delete,create,drop on the TableName table dbname the database, and set the password to 123456.

There are a lot of permissions to table operations like alter and so on

' User1 ' @'192.168.155.1'123456';

Assign the user user2 from 192.168.155.1 to all operations on the database dbname all tables, and set the password to 123456.

' User2 ' @'192.168.155.1'123456';

Assign the user User3 from 192.168.155.1 to all operations on all tables in all databases, and set the password to 123456.

' User3 ' @'192.168.155.1'123456';

Assign the native user user4 permissions to all operations on all tables in all databases, and set the password to 123456.

' User4 '@'localhost'123456';

Open external access to firewall mysql3306 ports

After upgrading to 7, CentOS replaced the original iptables with Firewalld. Below is a note on how to open Linux ports using FIREWALLD

--zone: Scope, the network region defines the trusted level of the network connection. This is a one-to-many relationship, which means that a connection can only be part of a region, and a region can be used for many connections

--add-port: Add port and communication protocol in the format: Port/Communication Protocol, protocol TCP or UDP

--permanent: Permanent, without this parameter the port access fails after the system restarts

[Email protected]/]# firewall-cmd--zone= public --add-port=3306/tcp--permanent

Restarting the firewall

[Email protected]/]# Firewall-cmd--reload

-----------------------------------------------------------------------

How to change your password after you forget the root password

Stop MySQL service, or command systemctl stop MySQL

[[Email protected]/]# service MySQL stop

Enter/usr/local/mysql

[Email protected]/]# cd/usr/local/mysql/

Start MySQL via Mysqld_safe and do not start the Grant-tables authorization form when you start MySQL

[Email protected] mysql]#/bin/mysqld_safe--basedir=/usr/local/mysql \

--datadir=/usr/local/mysql/data \
--skip-grant-tables &
Log in to MySQL

[[email protected]/]# mysql-u root MySQL

Change root password

Mysql>update user SET Password=password ("new_password") WHERE user='root  ';

Refresh Permissions

Mysql>flush privileges;

Quit MySQL

Reprinted from Http://www.jb51.net/article/104419.htm

CentOS 7 compilation installs MySQL and adds MySQL to system service

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.