Linux below mariadb Management Command base use

Source: Internet
Author: User

MariaDB is a part of MySQL, and for some reason it replaced MySQL as the default database for Rhel/centos 7. Operation against the database we often do the operation is to delete and change, then introduce the next mariadb some basic management commands.

(PS: # This represents the shell's prompt,> here represents the MariaDB shell prompt.) )

1. View MariaDB installed version

To view the current version of the installed database, enter the following command in the terminal:

# mysql-version

This command will tell you the current version of the database. Alternatively, you can run the following command to view the version details:

# mysqladmin-u Root-p Version

2, Login MariaDB

Log on to the MariaDB server and run:

# mysql-u Root-p

Then enter the password to log in.

3. List all databases

List all the databases currently owned by MariaDB when you log in to MariaDB and run:

> show databases;

4. Create a new database

Create a new database in MariaDB and run it after logging in to MariaDB:

> CREATE database test;

If you want to create a database directly at the terminal, run:

# mysqladmin-u user-p Create test

Ps:test is the name of the new database.

5. Delete Database

Delete the database and run it in a MariaDB session that is logged in:

> drop database test;

In addition you can also run,

# mysqladmin-u root-p Drop test

6. Create a new user

To create a new user for the database, run:

> CREATE USER ' dbuser ' @ ' localhost ' identified by ' password ';

7. Authorized users to access a database

Authorize users to access a database and run:

> GRANT All privileges the test.* to ' dbuser ' @ ' localhost ';

Gives the user Dbuser permission to fully manipulate the database named Test. We can also restrict the user to only SELECT, INSERT, DELETE permissions.

To give permission to access all databases, replace test with *. Like this:

> GRANT All privileges on * * to ' dbuser ' @ ' localhost ';

8. Backup/Export Database

To create a backup of a single database, run the following command in a terminal window,

# mysqldump-u Root-p Test > Test.sql

To create a backup of multiple databases at once, run:

# mysqldump-u root-p--databases db_name1 db_name2 > Db_name12_backup.sql

To export all databases at once, run:

# mysqldump-u Root-p--all-databases > All_dbs.sql

9. Recovering the database from backup

Restore the database from the backup, run:

# mysql-u ROOT-P database_name < Db_backup.sql

However, this command succeeds only if there is no database with the same name in advance. If you want to restore the database data to a database that already exists, you need to use the Mysqlimport command:

# mysqlimport-u ROOT-P database_name < Db_backup.sql

10. Change the password of the MariaDB user

Log in to MariaDB and switch to the ' MySQL ' database:

# mysql-u Root-p

> Use test;

Then run the following command:

> Update user Set Password=password (' Your_new_password_here ') where user= ' dbuser ';

Next, Reload permissions:

> Flush Privileges;

Finally, you exit the session.

Linux below mariadb Management Command base use

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.