How to build an enterprise-level MySQL database server?

There are many ways to install MySQL database management system tools under the CentOS7 platform. We can choose a simple binary data package installation or a source package installation. Due to the flexibility of the source code installation method and compilation, we will use the source code installation method as In the demonstration case, the source code installation of MySQL is mainly divided into five steps: installing dependency packages, downloading MySQL source packages, configuring the installation environment, compiling and installing, and initializing the database.

It should be noted that MySQL5.6 uses cmake to build the installation architecture. If users insist on using the previous configure installation method, they can generate configure files through the BUILD/autorun.sh script in the source package to achieve traditional configuration installation.

No matter which method is used, you need to install the corresponding dependency packages before installing and deploying the MySQL database. Here, use yum to install these dependency packages in advance, and then download the source software through the MySQL official website for installation.

[root@localhost ~]# yum -y install gcc make cmake ncurses-devel libxm12-devel \

libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel

[root@localhost ~]# wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.11.tar.gz

During the installation process, you need to create user and group accounts for the database process. It should be a service process account, so this type of account does not need to log in to the operating system. It is safer to set Shell to /sbin/nologing. When MySQL is compiled and installed, you need to set the correct user and group for the software home directory.

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -r -s /sbin/nologin -g mysql mysql

[root@localhost ~]# tar -xzf mysql-5.6.11.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/mysql-5.6-11/

[root@localhost ~]# cmake . -DENABLE_DOWNLOADS=1

[root@localhost ~]# make && make install

[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql

After the database software is installed, you are asked to use the mysql_install_db script to initialize the database, use user to define the database account name, use basedir to define the software home directory, and datedir to define the database storage directory. After the initialization is complete, you need to copy the mysql main configuration file my.cnf to the /etc/ directory.

[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql \

--basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

[root@localhost ~]# cp /usr/local/mysql/my.cnf /etc/my.cnf

Through the above steps, we have completed the installation of the mysql database software. If you want to try to use the powerful mysql database management system, you need to use the mysqld_safe process to manually start the database service process or to manage the service through the startup script mysql.server provided by the software package process.

[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql &

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /erc/init.d/mysqld

[root@localhost ~]# chkconfig --add mysqld

[root@localhost ~]# chkconfig mysql on

[root@localhost ~]# PATH=$PATH:/usr/local/mysql/bin/

[root@localhost ~]# echo “export PATH=$PATH:/usr/local/mysql/bin” >> /etc/profilt

At this point, the MySQL database system has been installed and initialized, and we can use the mysqld startup script to implement the startup function. But in the UNIX environment, using the mysql_install_db program to initialize the database is to create a blank database test for testing by default, and the initialization program will also create a user table in the mysql database, which is the account and permissions of the mysql database system Table, in the initial situation, the table has the following problems.

l The root in the mysql.user table is the super administrator account. However, the account has no password by default, which may cause illegal users to directly access the database without a password.

l Anonymous accounts are created by default in mysql.user, and these accounts also have no password set. You can use the following commands to view the user account and password data created by mysql by default.

[root@localhost ~]# mysql -u root -e “SELECT User,Host,Password FROM mysql.user”

For this reason, MySQL provides a perl script program specifically to solve these problems. The premise of running the script is that the perl program has been installed in the operating system. After running the script, you will be prompted to enter the root password. Just press the Enter key for the first run. The program will ask whether to set a password for root user through a series of prompts, whether to remove anonymous users, whether to prohibit root remote login, whether to delete the test database, and whether to reload new data immediately. It is recommended to choose y for all questions, especially This step is necessary in an enterprise production environment.

[root@localhost ~]# /usr/local/mysql/bin/mysql_secure_installation

So far all the initialization operations of MySQL are completed.

MySQL management tools

mysql is a database system based on a client/server architecture. The mysql server runs as a daemon, and mysql is the main server process. When we need to perform any operation on the server, we need to use client software to connect to the server for operation. There are many mysql client programs, you can use the built-in software mysql, mysqladmin, mysqldump and other commands to perform data operations on the database, or you can design your own dynamic website to connect to the mysql database through the API to perform the same database operations. In addition, the mysql WorkBench tool can be downloaded from the mysql official website. This tool is a graphical mysql database client management program. Benjie will focus on the client software integrated with the mysql software package.

1. MySQL Tools

mysql is a simple command line SQL tool that supports interactive and non-interactive operation. It is very easy to use the mysql command. You only need to enter mysql in the system command terminal to enter the management page

[root@localhost ~]# mysql

If you use the mysqladmin or mysql_secure_installation program to set a password for the account, you need to specify the account name and password when you start the mysql program. After entering the interactive interface, you can enter the SQL statement to operate the database. After the SQL statement, you must use; or \g end. You can exit through exit when exiting the program.

[root@localhost ~]# mysql --user=user_name --password=your_password database name

l By creating a SQL statement script file in advance, we can use the mysql tool to perform data operations custom, as follows

[root@localhost ~]# cat script.sql

show tables;

select * from mysql.user\G

[root@localhost ~]# mysql db_name < script.sql > out.tab

Among them, script.sql is a SQL script file, and out.tabl is a redirected output file

l MySQL commands support a large number of options, the following are common MySQL options and descriptions.

--help,-? Display help information

--auto-rehash tab is automatically filled, the default is on

--auto-vertical-output automatically display vertically, if the display is too wide, it will be displayed in column format

--batch,-B do not use history files

--bind-address=ip_address Use a specific network interface to connect to the MySQL server

--database=dbname,-D dbname specifies the name of the database used

--defaule-character-set=charset_name set the default character set

--delimiter=str set statement delimiter

--host=host_name,-h host_name connect to the specified server through host

--password,-p use password to connect to MySQL server

--pager=[command] Use paging program to display page by page

--port=port_num Use the specified port number to connect to the server

--quick do not cache query results

--unfuffered refresh the cache after each query

--user=user_name,-u user_name Use the specified account to connect to the server

l The case is as follows

Use root account to connect to the server, login without password

[root@localhost ~]# mysql -u root

Use the root account to connect to the server and enter the mysql database by default;

[root@localhost ~]# mysql -u root mysql

Use the root account to connect to the server and log in with the password 123456

[root@localhost ~]# mysql -uroot -p123456

Use the root account to connect to the server 192.168.0.10 server, use the password 123456

[root@localhost ~]# mysql -uroot -p123456 -h 192.168.0.10

l Use mysqladmin tool

mysqladmin is a tool for performing management, you can use it to check the server's configuration, running status, and operations such as creating and deleting databases.

The syntax format is as follows:

mysqladmin [options] command parameters [command [command parameters]]

mysqladmin supports the following commands

create db_test Create a database named db_test

debug write debug information to the error log

drop db_test deletes the database named drop db_test and all the data tables in the database

extended-status displays server status variables and their values

flush-host flushes the cache information of all hosts

flush-logs flush all logs

flush-privileges reload the privilege data table

flush-status Clear status variables

flush-tables flush all data tables

kill id, id,... kill the server thread

password new-123456 Set new password

ping to check whether the server is available

reload reload the permission data table

refresh refresh all data tables and restart the log file

shutdown Shut down the server

Guess you like

Origin blog.csdn.net/wx_15323880413/article/details/108557963