Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

20.2.1 Configure the Mysql service


May 24, 2021 That's what Linux should learn



Chapter 18 of this book explains the causes and characteristics between MySQL and MariaDB database management system, and also praises MariaDB database, but MySQL database is still one of the most commonly used in the production environment of the relationship database management system, sitting on a large market share, and has been through more than a decade of continuous development to the industry to prove its stability and security. In addition, although Chapter 18 has explained the basic database management knowledge, but in order to further help you consolidate the foundation, this chapter is still here to integrate the MySQL database content, so that we can know the new at the same time.

When you install a service program using the Yum software repository, the system automatically works according to the full software configuration of the instruction set in the RPM package. B ut once you choose to install it using the source package, you need to do it yourself. F or the MySQL database, we need to create a user in the system called mysql, dedicated to running the MySQL database. Remember to set up the Bash terminal for such accounts as a nologin interpreter to prevent hackers from logging on to the server through the user to improve system security.

[root@linuxprobe cmake-2.8.11.2]# cd .. r oot@linuxprobe useradd mysql -s /sbin/nologin creates a directory for saving MySQL database programs and database files, and modifies the identity of the owners and groups of that directory to mysql. Among them, /usr/local/mysql is the directory used to hold the MySQL database service program, /usr/local/mysql/var is the directory used to hold the real database files.

(root@linuxprobe src) mkdir -p/usr/local/mysql/var (root@linuxprobe src) sqwn-rf mysql:mysql/usr/local/mysql next unzips, compiles, and installs the MySQL database service program. T he database is compiled using the cmake command, where the -DCMAKE_INSTALL_PREFIX parameter is used to define the saved directory of the database service program, the -DMYSQL_DATADIR parameter is used to define the directory of the real database file, and the -DSYSCONFDIR is the save directory that defines the MySQL database profile. Because the MySQL database service program is large, the compilation process is long, during which you can take a break.

[root@linuxprobe src]# tar xzvf mysql-5.6.19.tar.gz [root@linuxprobe src]# cd mysql-5.6.19/ [root@linuxprobe mysql-5.6.19]# cmake . - DCMAKE_INSTALL_PREFIX/usr/local/mysql -DMYSQL_DATADIR/usr/local/mysql/var-DSYSCONFDIR=/etc(root@linuxprobe mysql-5.6.19)make(root@linuxprobe mysql-5.9) In order for the MySQL database program to function properly, make install needs to first delete the default profile in the /etc directory, and then find a script called mysql_install_db in the save directory script of the MySQL database program, execute the script and use the user parameter to specify the corresponding account name of the MySQL service (which was created in the previous steps), Use the --baseir parameter to specify the saved directory of the MySQL service program, and use the --datadir parameter to specify the file save directory of the MySQL real database, so that the system database file can be generated and a new MySQL service profile can be generated.

(root@linuxprobe mysql-5.6.19) s rm -rf /etc/my.cnf (root@linuxprobe mysql-5.6.19) s cd/usr/local/mysql s/root@linuxprobe mysql s/scripts/mysql_install_db --user=mysql--based ir=/usr/local/mysql --datadir=/usr/local/mysql/var links the system's newly generated MySQL database profile to the /etc directory, and then copies the starter files in the program directory to the /etc/rc.d/init.d directory in order to manage the MySQL database service program through the service command. Remember to modify the permissions of the database script file to 755 so that the user has permission to execute the script:

(root@linuxprobe mysql) - ln -s my.cnf /etc/my.cnf (root@linuxprobe mysql) s cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld (root@linuxprobe mysql Chmod 755 /etc/rc.d/init.d/mysqld edits the newly copied MySQL database script file and modifies the basedir and datadir parameters on lines 46 and 47 to the saved directory of the MySQL database program and the file contents of the real database, respectively.

[root@linuxprobe mysql]# vim /etc/rc.d/init.d/mysqld .................. O mit some of the output information... 3 9 # 40 # If you want to affect other MySQL variables, you should make your changes 41 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. 4 2 43 # If you change base dir, you must also change datadir. T hese may get 44 # overwritten by settings in the MySQL configuration files. 4 5 46 basedir=/usr/local/mysql 47 datadir=/usr/local/mysql/var 48 .................. O mit some of the output information... A fter the script file is configured, you can start the mysqld database service with the service command. m ysqld is the service name of the MySQL database program, be careful not to write it wrong. The mysqld service program is then added to the boot startup item using the chkconfig command.

[root@Linuxprobe mysql]# service mysqld start Starting MySQL. S UCCESS! T he root@linuxprobe mysql?chkconfig mysqld on MySQL database program brings many commands, but the PATH variable of the Bash terminal does not contain the directories where these commands are stored, so we can't successfully initialize the MySQL database, and we can't use the commands that come with the MySQL database. T o permanently define the directory saved by the command into the PATH variable, you need to edit the /etc/profile file and write the appended command directory so that the physical device will take effect permanently the next time it restarts. If you do not want to take effect by restarting the device, you can also use the source command to load the /ect/profile file, at which point the new PATH variable can also take effect immediately.

[root@linuxprobe mysql]# vim /etc/profile .................. O mit some of the output information... 6 4 65 for i in /etc/profile.d/ .sh ; d o 66 if [ -r "$i" ]; t hen 67 if [ "${-# i}" != "$-" ]; t hen 68 . " $i" 69 else 70 . " $i" sgt;/dev/null 71 fi 72 fi 73 done 74 export PATH=$PATH:/usr/local/mysql/bin 75 unset i 76 unset-f pathmunge (root@linuxprobe mysql) s source /etc/profile/MySQL database service program also calls to some program files and library files. Since the MySQL database is currently installed as a source package, these files must now also be linked manually.

root@linuxprobe mkdir /var/lib/mysql /root@linuxprobe mysql/ ln -s/usr/local/mysql/lib/mysql/root@linuxprobe mysql?ln-smp/tmp/mysql.sock/var /lib/mysql/mysql.sock (root@linuxprobe mysql) ln-s/usr/local/mysql/include/mysql/usr/include/mysql Now that the MySQL database service program has been started, the various function files called are in place, and the MySQL database command is included in the PATH environment variable. Next, prepare to initialize the MySQL database, which has the same configuration process as the MariaDB database, only to end up being Theanks for using MySQL!

[root@linuxprobe mysql]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. ENTER CURRENT Password for root (Enter for none): Simply press Enter OK, SuccessFully Used Password, Moving on ... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y / N] Y (to set the password for the root administrator) New Password: Enter the database password to the root administrator RE-ENTER NEW Password: Enter the password Password Updated SUCCESSFULLY! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y / N] Y (Delete anonymous accounts) ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y / N] Y (Prohibition of the root administrator from logging in remote) ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y / N] Y (Delete Test Database and cancel access rights)

  • Dropping test database... ... Success!
  • Removing privileges on test database... ... S uccess! R eloading the privilege tables will ensure that all changes made so far will take effect immediately. R eload privilege tables now? ( refresh the authorization form so that the initialization of the settings takes effect immediately) ... S uccess! A ll done! I f you've completed all of the above steps, your MySQL installation should now be secure. T hanks for using MySQL! Cleaning up...