Home > Database > Mysql Tutorial > How to install mysql on linux ubuntu

How to install mysql on linux ubuntu

藏色散人
Release: 2021-11-26 14:32:26
Original
5564 people have browsed it

How to install mysql on linux ubuntu: 1. Open the terminal and update the software package list; 2. Install MySQL through "$ sudo apt-get install mysql-server mysql-client"; 3. Log in with the root account. Can.

How to install mysql on linux ubuntu

The operating environment of this article: ubuntu 16.04 system, mysql8, Dell G3.

How to install mysql on linux ubuntu?

【Linux】Installation and use of MySQL in Ubuntu16.04 environment

I have been writing a small function recently and want to store data in MySQL, so I have to do it locally MySQL is installed on Ubuntu 16.04 installed on the virtual machine for use. The installation and simple use process are recorded below.

1. Running environment

Ubuntu16.04

2. Open the terminal and update the software package list

$ sudo apt update
Copy after login

3. Install MySQL

$ sudo apt-get install mysql-server mysql-client
Copy after login

The following window will appear during the installation process. Here you need to fill in the password of the MySQL root account and confirm

4. Initialize the MySQL security script

 $ sudo mysql_secure_installation
Copy after login

mysql_secure_installation will involve whether to modify the password of the root account, whether to remove anonymous users, whether to allow remote login, whether to delete the test database, etc.

5. After installation, we first log in with the root account and enter the root account password set during installation.

$ mysql -u root -p
Copy after login

6. Create MySQL database and user

$ create database blogdata;   # 创建一个名为blogdata的数据库
$ grant all on blogdata.* to 'bloguser' identified by 'test1234';    #创建用户bloguser
Copy after login

## You can view the database:

$ show databases;
Copy after login

7. First exit the root account (quit) and log in to MySQL with the newly created user

$ mysql -u bloguser -p blogdata
Copy after login

8. Create a table

CREATE TABLE article (id INT, name VARCHAR(300), created_time DATETIME, view_num INT, com_num INT, channel VARCHAR(20), get_time DATETIME);
Copy after login


9. Insert data

INSERT INTO article (id,name,created_time,view_num,com_num,channel,get_time) VALUES(1,"test","2019-11-20 10:00:00",2,1,"bky","2019-11-22 14:00:00");
Copy after login


## 10. Simple query

select * from article;
Copy after login

11. Other commands

Exit the MySQL command line:

mysql> quit
Copy after login

View the MySQL running status:

$ sudo systemctl status mysql.service
Copy after login

Stop the MySQL database service:

$ sudo systemctl stop mysql.service
Copy after login

Start the MySQL database service:

$ sudo systemctl start mysql.service
Copy after login

Restart the MySQL database service:

$ sudo systemctl restart mysql.service
Copy after login

View the MySQL configuration file:

$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Copy after login

Recommended learning: "mysql video tutorial

"

The above is the detailed content of How to install mysql on linux ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template