In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is MariaDB?
MariaDB is a branch of MySql. Looking at the history of database development, we know that MySql database has not only changed ownership twice, but also been left out in the cold (first acquired by sun, then acquired by Oracle). Because Oracle has its own database, and only Oracle's own employees can carry out MySql research and development, after Mr. Widenius, the father of MySQL, left Sun, he felt that it was very unreliable to rely on Sun/Oracle to develop MySQL, so he decided to open another branch, which is called MariaDB.
MariaDB is not just a substitute for Mysql, its main purpose is to innovate and improve the technology of Mysql.
MariaDB is a new development based on the original technology of MySql. At the same time, it is compatible with most of the original technology of MySql. For developers, it is almost impossible to feel any difference. At present, MariaDB is the fastest growing branch version of MySQL, and the new version has been released faster than the official MySQL version of Oracle.
LAMP architecture is very popular for a time, which is inseparable from the free and easy-to-use of MySQL, but after Oracle acquired Sun, many companies began to worry about the open source prospect of MySQL, and the recent move to further close the source of Oracle is even more reassuring, and many Internet companies have begun to seek alternatives to MySQL. MariaDB continues to maintain the concept of open source, a steady stream of new versions, providing unlimited possibilities for Internet technology, while many Internet giants have migrated and used MariaDB, so we will start to learn MariaDB.
Start installing MariaDB 1 to prepare the experimental environment
First, go to the official website of MariaDB to download the binary installation package of MariaDB, and download the address https://downloads.mariadb.org/.
Prepare a clean system that does not have MySql installed.
Prepare user and data directories
First prepare the users and user groups that the database can use.
# add a user group named mysql, and specify gid-r to create the system user group groupadd-r-g 306 mysql#-r to create the system user #-g means to execute the group to which the gid is 30 minutes-u means to specify uid to create a home directory #-d to specify the path to the home directory # mysql wants to add the user name useradd-r-g 306-u 306-m-d / app/data mysql
Specify the data directory, which serves as the location to store the database. Take / app/dbdata as an example.
Chown mysql:mysql / app/dbdata
Let's use a dynamic diagram to demonstrate the above two steps.
Three-preparation binary program
For packages that have been compiled in binary format, we can usually use the database directly after decompression. But in fact, it's not that simple. If we have ever compiled the process package ourselves, we will know that in the process of compiling the binary program, we need to specify the directory of some script, or the path to the binary execution program. The same is true for MariaDB, because we downloaded the compiled binary package, so the program we unzipped should also be placed in a fixed directory, which is / usr/local/mysql.
Here are the steps to extract the binary, but instead of creating the mysql directory directly, we set up a soft connection to point to the directory we extracted.
# Unzip the compressed file to the / usr/local path [root@localhost] # tar xvf mariadb-10.2.8-linux-x86_64.tar.gz-C / usr/local # change the directory [root@localhost ~] cd / usr/local/# to establish a soft connection for the decompressed path [root@localhost local] # ln-sv mariadb-10.2.8-linux-x86_64/ mysql# to view the Soft connection [root@localhost local] # ll-d m*drwxrwxr-x 12 1021 1004 290 Aug 18 04:16 mariadb-10.2.8-linux-x86_64lrwxrwxrwx 1 root root 28 Sep 27 09:39 mysql-> mariadb-10.2.8-linux-x86_64/# permission to modify directories Give the mysql user all the highest privileges. [root@localhost local] # chown-R root:mysql / usr/local/mysql/ [root@localhost local] # ll-d m*drwxrwxr-x 12 root mysql 290 Aug 18 04:16 mariadb-10.2.8-linux-x86_64lrwxrwxrwx 1 root root 28 Sep 27 09:39 mysql-> mariadb-10.2.8-linux-x86_64/
Let's take a look at what is contained in the extracted directory.
[root@localhost mysql] # lltotal 176drwxrwxr-x 2 root mysql 4096 May 3 02:05 bin-rw-r--r-- 1 root mysql 17987 Aug 17 18:05 COPYING-rw-r--r-- 1 root mysql 86263 Aug 17 18:05 COPYING.thirdparty-rw-r--r-- 1 root mysql 2275 Aug 17 18:05 CREDITSdrwxrwxr-x 3 root mysql 18 Aug 18 04:16 data-rw-r--r-- 1 root mysql 8245 Aug 17 18:05 EXCEPTIONS-CLIENTdrwxrwxr-x 3 root mysql 19 Aug 18 04:15 include-rw-r--r-- 1 root mysql 8694 Aug 17 18:05 INSTALL-BINARYdrwxrwxr-x 4 root mysql 318 May 3 02:05 libdrwxrwxr-x 4 root mysql 30 Aug 18 04:16 mandrwxrwxr-x 11 root mysql 4096 Aug 18 04:16 mysql-test-rw-r--r-- 1 root mysql 2371 Aug 17 18:05 README.md-rw-r--r-- 1 root mysql 19510 Aug 17 18:05 README-wsrepdrwxrwxr-x 2 Root mysql 30 Aug 18 04:16 scriptsdrwxrwxr-x 30 root mysql 4096 Aug 18 04:16 sharedrwxrwxr-x 4 root mysql 4096 Aug 18 04:16 sql-benchdrwxrwxr-x 3 root mysql 275 Aug 18 04:16 support-files
Bin: the directory where executable binaries are stored, where the client program mysql is located.
COPYING: copyright and open source information
COPYING.thirdparty: copyright information
CREDITS: some information about the MariaDB Software Foundation, including the domestic Internet giant Ali
Data: the default database storage directory, which will be stored if we do not specify a database storage directory in the first place.
EXCEPTIONS-CLIENT: exception
Some program files required by include:MariaDB
INSTALL-BINARY: installation help documentation, which can be read in detail, is of great help to the installation of the database
Lib: library files needed for the software to run
Man: help documentation for software
Mysql-test: the test component of the database
Scipts:mysql initializes the script file to be used during initialization. Read through the script to understand the installation process of Mysql.
Share: shared file content
Support-files: the configuration file or documentation needed for mysql to function properly is important, and if we want to customize the configuration file, we need to refer to the configuration file here to define it.
One thing to note here: the data directory is the path where the database is stored, which we specified manually before. In actual production, enterprise data is growing rapidly, and database files may be very large, so it is best to assign the directory to a separate disk, or a large partition, or use logical volumes to avoid a failure due to insufficient physical space.
Four prepare the configuration file
MariaDB configuration files can be stored under multiple paths. However, the lookup order of configuration files is fixed. As a result, the configuration file has priority, and the subsequent configuration will overwrite the previous configuration (if the configuration parameters are the same). We refer to the configuration file in support-files under the MariaDB installation path, create our own configuration file and store it in / etc/mysql/my.cnf
# create a configuration file path [root@localhost ~] # mkdir / etc/mysql [root@localhost ~] # cd / etc/mysql# copy the reference file to the mysql path we created [root@localhost mysql] # cp / usr/local/mysql/support-files/my-huge.cnf / etc/mysql/my.cnf
Then in this configuration file, add some of the directories and information we just specified. This is shown in the following figure.
As we said earlier, the lookup of configuration files is performed in a certain order. When MariaDB is installed successfully, execute the following command to see the order in which the configuration files are found.
# create configuration file path [root@localhost ~] # mkdir / etc/mysql [root@localhost ~] # cd / etc/mysql# copy the reference file to the mysql path we created [root@localhost mysql] # cp / usr/local/mysql/support-files/my-huge.cnf / etc/mysql/my.cnf 5 create a database file
Go to the / usr/local/mysql/ path and create the database file. Specify the database storage directory and default user while creating the database.
[root@localhost mysql] # cd / usr/local/mysql/ [root@localhost mysql] #. / scripts/mysql_install_db-- datadir=/app/dbdata-- user=mysql# switch to the database storage path we specified, and you can see some related files. Each path in this is a database. [root@localhost mysql] # cd / app/dbdata/ [root@localhost dbdata] # lsaria_log.00000001 ib_buffer_pool ib_logfile0 mysql mysql-bin.index performance_schemaaria_log_control ibdata1 ib_logfile1 mysql-bin.000001 mysql-bin.state test VI prepare log file
Because the log paths for CentOS 6 and CentOS 7 are different, the paths to the log files created are also different. / var/log/mysqld.log in CentOS6 and / var/log/mariadb/mariadb.log in CentOS 7
# create file path [root@localhost mysql] # mkdir / var/log/mariadb# create log file [root@localhost mysql] / var/log/mariadb/mariadb.log# modify file permissions [root@localhost mysql] # chown mysql / var/log/mariadb/mariadb.log
If you are not sure which files should be created in this step, you can first perform step 7, and then follow the error prompt in step 7 to create the files we need.
Prepare the service script and start the service
Copy the service script for mysql to the service directory. Because CentOS7 is compatible with earlier versions of the service, let's just copy the script directly to the / etc/init.d/ directory.
# copy the script of mysql to the service directory [root@localhost mysql] # cp support-files/mysql.server / etc/rc.d/init.d/mysqld# and add the mysql service to boot [root@localhost mysql] # chkconfig-- add mysqld [root@localhost mysql] # chkconfig-- listNote: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]' .mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:offnetconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:offnetwork 0:off 1:off 2:on 3:on 4:on 5:on 6 : off# starts MySQL service [root@localhost mysql] # service mysqld startStarting mysqld (via systemctl): [OK]
If we do not specify a log file or specify a log file in step 6, but forget to modify the permission, this step will go wrong, but don't worry if you make a mistake, just modify it a little bit according to the prompt.
In this step, we copied the mysql service script to the / etc/rc.d/init.d/ path because CentOS 7 is compatible with CentOS 6 service mode. Of course, it can also be done according to the service management style of CentOS 7, and the configuration file is located in the / usr/lib/systemd/system path.
Eight configure client environment variables
After completing the first few steps, we have done most of the work, and the service has been started, and we can use the ss tool to see if port 3306 is open. But at this point, if we use the mysql command to access the mysql database through the client, we will prompt that the mysql command cannot be found, so we need to specify the environment variable of the mysql command. As we said earlier, some binary executables after mysql extraction are located in the / bin folder of the unzipped directory, so we add this path to the environment variable.
# specify a separate path to modify the environment variable, which is easy to manage. [root@localhost mysql] # cat / etc/profile.d/mysql.shexport PATH=/usr/local/mysql/bin:$PATH# execute this script to make the environment variable take effect [root@localhost mysql] #. / etc/profile.d/ mysql.sh8 security initialization
After completing step 7, we have been able to access the data smoothly, even anonymous access. However, at this time, the database is not secure enough and can not be used in actual production, so we need to initialize the database safely.
We initialize the database according to the security initialization script provided in the installation file, and take a closer look at the dynamic picture below.
The following is a detailed explanation of the modified items in the figure
# do you want to reset the root user's password Set root password? Do you want to delete anonymous user Remove anonymous users? Does y # not allow root users to log in to Disallow root login remotely remotely? Do you want to delete the test database Remove test database and access to it? Reload the available database table Reload privilege tables now? [Y/n] y
Above, we have described in detail the whole process of installing MariaDB 10.2.8 in CentOS 7. And we only have a simple configuration, in the actual production, will often use MariaDB, so the entire installation process into a script, may also be a good choice. If you have any questions, please leave a message.
Personal blog address: http://www.pojun.tech/ welcome to visit
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.