Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE pytest;
Query OK, 1 row affected (0.00 sec)
mysql>
You can see if the new database was created by using the SHOW command:
Click here to view code image
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| pytest |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql>
This code shows that it was successfully created. You should now be able to connect to the new
database with the USE statement:
mysql> USE pytest;
Database changed
mysql> SHOW TABLES;
Empty set (0.00 sec)
mysql>
The SHOW TABLES command allows you to see if there are any tables created. The Empty set
result indicates that there aren’t any tables to work with yet. Before you start creating tables, though,
there’s one other thing you need to do.
Creating a User Account
So far you’ve seen how to connect to the MySQL server by using the root administrator account. This
account has total control over all the MySQL server objects—very much as the root Linux account
has complete control over the Linux system.
It’s extremely dangerous to use the root MySQL account for normal applications. If there were a
breach of security in the application and an attacker figured out the password for the root user
account, all sorts of bad things could happen to your system (and data). To prevent that, it’s wise to
create a separate user account in MySQL that has privileges only for the database used in the
application. You do this with the GRANT SQL statement, as shown here:
Click here to view code image
mysql> GRANT SELECT,INSERT,DELETE,UPDATE ON pytest.* TO test@localhost
IDENTIFIED by 'test';
Query OK, 0 rows affected (0.00 sec)
mysql>