Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ubuntu installation mysql database tutorial


May 16, 2021 MySQL



Ubuntu is a popular Linux operating system that is not only easy to use, but also very compatible with Windows. So how do you install mysql database under ubuntu?

Installing the mysql database on Ubuntu is generally done in two ways, using the Ubuntu Software Center or apt command, and the process is relatively simple.


1, using Ubuntu Software Center installation

Open Ubuntu Software Center, query mysql in the search box in the upper right corner, and select MySQL Server, click Install.


2, the use of apt command installation

Open the terminal to execute "sudo apt-get install mysql-server".


MySQL initial configuration

After successfully installing mysql, you can log in directly using the root account, noting that the account does not have a password by default. T herefore, in order to secure the database, you need to set the password for the root user the first time.

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "<password>";

Just replace the password you want to set with the one in the command above. O nce you've set your password, you'll need to enter your password if you sign in with a root user, such as:

$ mysql -u rootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)$ mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 75Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 


Establish a database of independent users

Root users have all the operational rights to the database and therefore cannot be easily used by others. I n a MySQL instance, we can create multiple databases that might be separate projects, and the operational roles of each database would be different. F or this, we can specify the user's access for different databases.

首先使用root角色创建一个数据库mysql> create database db_web_monitor然后将这个数据库授予一个叫xavier的用户使用mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";

This allows you to use xavier users, the password for xavier to log on to mySQL operation on db_web_monitor database.

$ mysql -u xavierERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)$ mysql -u xavier -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 77Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || db_web_monitor     || test               |+--------------------+3 rows in set (0.00 sec)mysql> 

Open remote login rights

1. First modify mySQL's profile to allow remote login monitoring.

$ sudo vi /etc/mysql/my.cnf找到bind-address所在行 45 # Instead of skip-networking the default is now to listen only on 46 # localhost which is more compatible and is not less secure. 47 bind-address        = 127.0.0.1将 bind-address值修改为本机IP即可。注意注释说明,如果是较老版本的MySQL,此处就应该是skip-networking,直接将其注释即可。

2. Give the user remote login rights.

mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";

In this way, xavier users can access the local MySQL via IP on any host and db_web_monitor the database


Recommended reading:

Ubuntu official help documentation

MySQL tutorial