Nội dung text Linux Chapter IX - MY SQL Server.pdf
MYSQL Database Server What is MySQL? MySQL is a relational database management system (RDBMS) developed by Oracle that is based on structured query language (SQL). A database is a structured collection of data. It may be anything from a simple shopping list to a picture gallery or a place to hold the vast amounts of information in a corporate network. In particular, a relational database is a digital store collecting data and organizing it according to the relational model. In this model, tables consist of rows and columns, and relationships between data elements all follow a strict logical structure. An RDBMS is simply the set of software tools used to actually implement, manage, and query such a database. MySQL is integral to many of the most popular software stacks for building and maintaining everything from customer-facing web applications to powerful, data-driven B2B services. Its open-source nature, stability, and rich feature set, paired with ongoing development and support from Oracle. MySQL Packages Mysql and mysql-server packages need to be installed to set up MySQL. Following MySQL packages come with the Red Hat Linux distribution: mysql — This software package contains a lot of MySQL client programs (in /usr/bin), several client shared libraries, the default MySQL configuration file (/etc/my.cnf), a few sample configuration files, files to support different languages, and documentation. mysql-server — This software package contains the MySQL server daemon (mysqld) and the mysqld start-up script (/etc/init.d/mysqld). The package also creates various administrative files and directories needed to set up the MySQL databases. mysql-devel — This software package contains libraries and header files required for developing MySQL applications. php-mysql — This software package contains a shared library that allows PHP applications to access MySQL databases. This basically allows you to add PHP scripts to your Web pages that can access your MySQL database. Installation of MYSQL To install MySQL, we’ll need to visit the MySQL community Yum Repository which provides packages for MySQL. To install MySQL on your Linux machine simply use following command
[root@dns etc]# wget https://repo.mysql.com/mysql80-community-release-el8- 1.noarch.rpm [root@dns etc]# yum install mysql80-community-release-el8-1.noarch.rpm [raju@localhost ~]$ sudo yum install mysql-server To check for current version of Centos Cat /etc/redhat-release Step 2 — Starting MySQL service Start the daemon with the following command: sudo systemctl start mysqld sudo systemctl status mysqld If MySQL has successfully started, the output should contain Active: active (running). Step 3: Configuring the MySQL Server Step I: MySQL user and Group Like most server software in Red Hat Linux, the MySQL server relies on a start-up script and a configuration file to provide the service. Server activities are logged to the mysqld.log file in the /var/log directory. There are also mysql user and group accounts for managing MySQL activities. mysql user/group accounts When the MySQL software is installed, it automatically creates a mysql user account and a mysql group account. These user and group accounts are assigned to MySQL files and activities. In this way, someone can manage the MySQL server without needing to have root permission. The mysql user entry appears in the /etc/passwd file as follows: mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin The mysql entry just shown indicates that the UID and GID for the mysql user is 27. The text string identifying this user account is "MySQL Server." The home directory is /var/lib/mysql. The home directory identified will contain directories that hold each table of data you define for the MySQL server.
Step II: root/administrative user password set To administer MySQL, root user is the default user. Root password can be set as below # mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 0 Step III : Setting MySQL options You can set options that affect how the MySQL applications behave by using options files or command-line arguments. The MySQL server reads the following options files when it starts up (if those files exist): /etc/my.cnf — Contains global options read by mysqld (server daemon) and mysql.server (script to start the server daemon). /var/lib/mysql/my.cnf — Contains options primarily for the mysqld daemon. -defaults-extra-file — You can identify a file on the command line that contains options to be used by the server. For example, the following command would cause the file /home/jim/my.cnf to be read for options after the global options and before the user-specific options: # mysqld --defaults-extra-file=/home/jim/my.cnf
$HOME/.my.cnf — Contains user-specific options. (The $HOME refers to the user's home directory, such as /home/susyq.) Creating the my.cnf configuration file Global options that affect how the MySQL server and related client programs run are defined in the /etc/my.cnf file. The default my.cnf file contains only a few settings needed to get a small MySQL configuration going. The following is an example of the /etc/my.cnf file that comes with MySQL: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Step 4 — Testing MySQL We can verify our installation and get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the following command to connect to MySQL as root (-u root), prompt for a password (-p), and return the version. [root@localhost ~]# mysqladmin -u root -p version Enter password: mysqladmin Ver 8.0.26 for Linux on x86_64 (Source distribution) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 8.0.26 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 9 min 11 sec