Create and delete a MySQL database – gridscale

What’s the matter?

For years MySQL and MariaDB have been the most popular OpenSource Database Managment Systems worldly concern wide. So it is no surprise that most of the coarse software support them natively. There are actually merely two large areas of databases. relational databases ( MySQL, PostgreSQL, Oracle and similar ), and alleged non-relational databases, besides called no-SQL databases. MySQL and MariaDB belong to to the relational databases.

We work with these databases very frequently and have found that most tasks can be done with a handful of commands. In this article, we will guide you through the commands of MySQL or MariaDB to create a new database. then we will show you how to delete the new ( or any other ) database .

Starting MySQL Console

inaugural, log on to your MySQL or MariaDB server. To do this, connect to your server via SSH. On Windows, you can use the plan PuTTY, on Linux, use any terminal program ( like xTerm ), and on MAC OS X you just use the built-in terminal ( type “ terminal ” in the Spotlight search and confirm with Enter ). If you are logged on to the waiter, you can merely log on to your MySQL or MariaDB server. If you have not so far created a new exploiter who has the rights to create new databases, use the exploiter ‘ root ’ .

Log on as root user on MySQL

The registration process is very simple. Once you are logged in to your waiter, you simply use mysql-binary to login. If your MySQL or MariaDB waiter has set a password, then you call the plan as follows :

Copymysql -u root -p

If you have not set a password for the drug user rout, do not use the parameter ‘ -p ’. If everything goes well, then you should see the stick to output signal :

[email protected]:~# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 98 Server version: 5.5.47-0+deb8u1 (Debian) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

directly after logging in as an administrative user ( rout ), you can create newly databases or display existing databases .

List all Databases

If you have a newly install system with a new MySQL or MariaDB case, then credibly not all besides many databases exist. First of all, let MySQL or MariaDB show you all existing databases with the command ‘ SHOW DATABASES ; ’. Make certain you have the command in your SQL cabinet with the semicolon ; at the conclusion .

+-------------------- +| Database           |+ -- -- -- -- -- -- -- -- -- -- +
 | information_schema |
 | mysql |
 | performance_schema | 
 + -- -- -- -- -- -- -- -- -- -- +
 3 rows in sic ( 0.00 secant )
 mysql >

As you see, my server is bore and evacuate .

Create a MySQL or MariaDB database

Creating a new database under MySQL or MariaDB is good angstrom easily as listing the existing databases. Just use the SQL command ‘ CREATE DATABASE ;’ to create a Database with the name .

mysql> CREATE DATABASE blog; 
Query OK, 1 row affected (0.00 sec) 

If everything went well, you just created a database called web log. If you nowadays list all your databases again, you can find the newly created database in the end product :

| Database           | 
| information_schema | 
| blog               | 
| mysql              | 
| performance_schema |
4 rows in set (0.00 sec)

Deleting a MySQL or MariaDB database

If you delete a database directly with the command agate line tool, be certain to delete the correct one. Once the database is deleted, there is normally no going back. First tilt all databases on your server. Use the command ‘ SHOW DATABASES ; ’ in the mysql-console like in the case above. now copy the mention of the database you want to delete. To do delete a database you need the command ‘ DROP DATABASE ’. The syntax is alike to creating a database. ‘ DROP DATABASE ;’, where is the name of the database you want to delete. An exemplar could look like this :

 mysql > DROP DATABASE web log ;
 Query OK, 0 rows affected ( 0.01 second )
 mysql > 

The mysql-console is not very helpful here. If everything went correctly it will show you a elementary “ OK ”. Use the command ‘ SHOW DATABASES ; ’ to double check the database was deleted .

More Information

How to create a User and concede privileges on MySQL and MariaDB. ( german merely )

reservoir :
Category : Tutorial

Related Posts

Trả lời

Email của bạn sẽ không được hiển thị công khai.