Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

In this command, replace secretword with whatever you want to be the
password for the root user. You can use this same command with other
usernames to set or change passwords for other database users.


After you enter a password, you can exit the MySQL client by typing exit at
the command prompt.


Creating a Database in MySQL


In MySQL you create a database by using the CREATE DATABASE
statement. To create a database, you connect to the server by typing mysql
-u root -p and pressing Enter. After you do so, you are connected to the
database as the MySQL root user and prompted for a password. After you
enter the password, you are placed at the MySQL command prompt. Then
you use the CREATE DATABASE command. For example, the following
commands create a database called animals:


Click here to view code image
matthew@seymour:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 3.23.58


Type    'help;' or  '\h'    for help.   Type    '\c'    to  clear   the buffer.

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

Another way to create a database is to use the mysqladmin command, as
the root user, with the create keyword and the name of a new database. For
example, to create a new database named reptiles, you use a command
line like this:


Click here to view code image
matthew@seymour:~$ sudo mysqladmin -u root -p create reptiles
Granting and Revoking Privileges in MySQL


You probably want to grant yourself some privileges, and eventually you will
probably want to grant privileges to other users. Privileges, also known as
rights, are granted and revoked on four levels:


Global  level—These rights  allow   access  to  any database    on  a   server.
Database level—These rights allow access to all tables in a database.
Table level—These rights allow access to all columns within a table in a
Free download pdf