Install and set MariaDB in CentOS

Source: Internet
Author: User

Author: Tie

Date: January 1, December 27, 2013

For more information, see install MariaDB using YUM in Centos.

Note: First, you must be able to connect to the Internet. If you cannot directly access it, You can also set a proxy. For details, refer to: setting a yum proxy on an intranet machine.

The permission to use yum must be a root user. If not, you can add sudo before the shell command, that is, switch to the super administrator for operations. You may need to enter the password.

1. Add the yum data source;

We recommend that you name MariaDB. repo a similar name:

Cd/etc/yum. repos. d/vim/etc/yum. repos. d/MariaDB. repo and then write the file content:
# /etc/yum.repos.d/MariaDB.repo# MariaDB 5.5 CentOS repository list - created 2013-12-23 10:27 UTC# http://mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/5.5/centos6-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
The content of this file is to refer to the official website, and generated from the official website, set the installation source warehouse specific address: https://downloads.mariadb.org/mariadb/repositories/
After selecting the operating system version, you can view and set the installation source for other operating systems.

2. Install the database

# yum remove MariaDB-server MariaDB-clientyum -y install MariaDB-server MariaDB-client
If you want to delete the old database, you can use remove. The parameter-y is OK and no prompt is required. Here, the server and client are installed. Generally, you can install these two servers.

3. Start the database

If you do not need to perform other operations, you can start the database and test it now.

# Viewing the mysql status; disabling the database # service mysql status # service mysql stop # Starting the Database service mysql start
4. Modify the root password
# Modify the root password mysqladmin-u root password 'root'
Because the root password after installation is empty, you need to set it. If it is a test server, you can directly use the root password. If it is not important, you can set it to be the same as the user name, so that you can't remember it again.

If it is an important server, use a complex password, such as a mailbox and characters of various combinations of rules.

5. log on to the database

mysql -u root -p
If it is a local machine, you can directly use the above command to log on, of course, you need to enter the password. If it is another machine, it may need the following form:
mysql -h 127.0.0.1 -P 3306 -u root -p

6. Simple SQL Testing

> -- View the MySQL status; -- display the supported engine show engines; -- display all databases show databases; -- switch the database context to set the default database use test for the current session; -- show all tables in the database show tables; -- CREATE a table create table t_test (id int (11) unsigned not null AUTO_INCREMENT, userId char (36), lastLoginTime timestamp, primary key (id) ENGINE = InnoDB default charset = utf8; -- insert test data into t_test (userId) values ('admin'), ('hahaha '); -- simple query select * from t_test; select id, userId from t_test where userId = 'admin ';
7. Modify the data storage directory
The default data of mysql and MariaDB is stored in the/var/lib/mysql/directory. If you do not want to put it here, or want to separate the program from the data, or for disk reasons, you need to switch to another path, you can modify DatadirSystem variables to achieve the goal.
# Stop Database service mysql stop # create a directory, if no, mkdir/usr/local/ieternal/mysql_data # copy the default database to the new location #-a Command copies the file attributes together, otherwise, cp-a/var/lib/mysql/usr/local/ieternal/mysql_data # back up the original data cp-a/etc/my. cnf/etc/my. cnf_original # view/etc/my. the cnf file can be found # MariaDB has only one containing statement # the configuration file to be modified is/etc/my. cnf. d/server. cnfcp/etc/my. cnf. d/server. cnf/etc/my. cnf. d/server. cnf_originalvim/etc/my. cnf. d/server. cnf
Then press I to enter the editing mode. you can insert relevant content. Use the upper, lower, and lower keys on the keyboard to move the cursor. After editing, Press ESC to exit the editing mode (enter the command mode), and then enter the command : WqSave and exit
# Add [mysqld] datadir =/usr/local/ieternal/mysql_data/mysqlsocket =/var/lib/mysql in the mysqld section of the file. sock # default-character-set = utf8character_set_server = utf8slow_query_log = onslow_query_log_file =/usr/local/ieternal/mysql_data/slow_query_log.loglong_query_time = 2
Among them, only datadir and socket are important, while default-character-set is known by mysql, but mariadb5.5 is not known, which is equivalent to character_set_server.

Then restart MySQL.
service mysql start

In the next article, MariaDB will be copied (Master --> Slave ).

Related Article

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.