Teach you how to install MySQL and MariaDB on Linux(Deepin)

I used to use the SQL server under win. I'm a little unfamiliar with MySQL. I may introduce some basic information. If there is any incorrect description, I'd like to ask the boss for advice

  1. The relationship between the two
  2. Install MySQL
  3. Install MariaDB (one line installation)
  4. Simple daily use

The relationship between the two

MariaDB and MySQL General relationship

MariaDB Database management system is MySQL A branch of, mainly maintained and adopted by the open source community GPL Licensing. One of the reasons for developing this branch is:
Oracle acquired MySQL After that, there will be MySQL The potential risk of closed source, so the community adopts the way of branching to avoid this risk.

MariaDB The aim is full compatibility MySQL,include API And command line, making it easy to become MySQL A substitute for.

MariaDB from MySQL Founder Michael·Vidnius led the development. He paid $1 billion earlier,
Will create their own company MySQL Sold SUN,Since then, with SUN Acquired by Oracle, MySQL Ownership also falls into Oracle In my hands.

MariaDB The name comes from Michael·Vidnius' daughter Maria (English: Maria)Your name.

MariaDB Until 5.5 Version, all in accordance with MySQL Version of. Therefore, use MariaDB5.5 People from MySQL5.5 Learned from MariaDB All functions of.
10 issued from November 12, 2012.0.0 Version start, no longer in accordance with MySQL Version number of the.
10.0.x Version 5.5 Version based, plus transplantation from MySQL 5.6 Version of the features and self-developed new features.

In terms of storage engine, 10.0.9 Use from version XtraDB(The name code is Aria)To replace MySQL of InnoDB. 

MariaDB of API Compatible with protocol MySQL,In addition, some functions have been added to support local non blocking operation and progress reporting.

This means that all use MySQL Your connectors, libraries, and applications will also be available in MariaDB Work next week.

On this basis, due to fear of Oracle MySQL A more closed software project, Fedora What's your plan Fedora 19 In order to MariaDB replace MySQL

Having said so much, let's summarize briefly

MariaDB is the same as MySQL
MariaDB is open source
MySQL is commercial
The founder is a person

Install MySQL

The first step to install MySQL is also the first step to install many other files. Change the source to domestic source
Change the source through the command line,

Open the terminal input (the copy and paste of the terminal is ctrl+shift+c/v)
If you don't want to use the terminal to modify, we can directly visualize it and modify it with a text editor

sudo edit /etc/apt/sources.list


Press enter to enter the editing page
Click a to edit, and then add # comments in front of the original deb
The Xiaobian here is replaced by Alibaba cloud

deb [by-hash=force] https://mirrors.aliyun.com/deepin/ apricot main contrib non-free

To exit insert mode, click Esc


In this case, entering: wq enter means saving and exiting
If the input is wrong, you can enter: q! Press enter to exit without saving, and then enter again to modify


Update the source after changing the source

sudo apt-get update

The process takes dozens of seconds

If you finish the modification through the terminal, you can see it directly Next download It's OK. Here's a visual modification of the text editor

Click this search button directly

/etc/apt

Then enter this directory and press enter directly

Right click the blank space and directly open the folder as an administrator

You need to enter a password to enable administrator mode

Right click to select the opening method - > open text editor


Then annotate the second line and add the source of Alibaba cloud to the third line

deb [by-hash=force] https://mirrors.aliyun.com/deepin/ apricot main contrib non-free


Then click ctrl+s to save and update the apt source

sudo apt-get update

The process takes dozens of seconds

Then download mysql-apt-config
Of course you can Download from official website However, the official website needs to log in before downloading

Just download it directly through deepin's browser

After downloading, double-click directly to run

Click Install, enter password authorization, install

Select the second debian buster and enter 2 directly

If you want to download other versions of MySQL, enter 1 and select it

If you are downloading MySQL 8 0, directly select ok and enter 4

Installation succeeded


Open the terminal and update the apt source

sudo apt-get update

Install MySQL through apt source

sudo apt-get install mysql-server


Enter y to confirm the installation

Then, you need to enter the password of MySQL in this interface (the password is not displayed, and the wrong one can be deleted. You can enter it normally)

After entering, confirm the entered password again


Just press enter here to confirm


The installation should be completed when it appears here

Then use the command line to check whether the installation is successful

sudo service mysql status


This interface input: wq exit

Then you can directly look at the following simple usage methods

Install MariaDB

sudo apt install mariadb-server mariadb-client
 Here are integrated commands. You can run them directly and install them with one click

Enter the command line, enter the password to confirm (the password of Linux is not displayed, just enter it. Sometimes the number key will lock itself), and then enter y to confirm the installation

Then the installation is successful

Briefly introduce some usage methods, which are similar to mysql

It's mainly to help you get started. What's more, you need to practice and learn slowly to improve yourself

start-up mysql service
sudo service mysql start
 close mysql service
sudo service mysql stop
 restart mysql service
sudo service mysql restart

MariaDB login to database

mysql -u root -p 

Log in to mysql with the root account. The password is blank by default. Access denied for user 'root' @ 'localhost' is displayed
Here we need to switch the end user to root

Switch the terminal to root

sudo -i


Then log in to the MariaDB database again

mysql -u root -p 

When the following figure appears, the login is successful

Here's why the host version is Debian instead of Deepin
Deepin is derived from Debian. Later, you will find that the format of the installation package is deb format
And other installation software specifications need to be installed in debian format

If you want to exit MariaDB, you can directly use the command statement to exit

The following three statements can exit directly
exit            
quit
\q

The next step is to use sql statements. We must pay attention to our sql statements
Plus mark
Plus mark
Plus mark

Display database
show databases

This is because there is no semicolon, so he will think that you have to enter other SQL statements and start the next line. Be sure to remember to add semicolons (the SQL server statement does not need to add semicolons. I was still fooling where I made a mistake when I just turned around)

First build a database

Create database demo
create database demo;
Display database
show databases

This is because there is no semicolon, so he will think that you have to enter other SQL statements and start the next line. Be sure to remember to add semicolons (the SQL server statement does not need to add semicolons. I was still fooling where I made a mistake when I just turned around)

Enter the demo database just created

Change the current database to demo
use demo

The database before the change is none, that is, no database is currently entered
After the change, it becomes a demo and has entered the demo database

If you want to switch to another database, you can also directly execute the statement of changing the database

Create data table users

Create a table with type int of id Column of type varchar of name column

create table users(
id int,
name varchar(50)
);

Display table

show tables;

Insert statement

insert users Method for each column in the table

insert into users values(1,'ZhangSan');

Data in query table

select * from users;

insert users Methods for some columns in the table

insert into users(id) values(2);


Data in query table

select * from users;

Delete statement

delete id Data for 2
delete from users where id = 2;


Change statement

change id Name of the user named 1

update users set name = 'NewZhangSan' where id = 1;

Delete table statement

delete users surface

drop table users;

Delete library statement

delete demo surface

drop database demo;

Keywords: Linux MySQL MariaDB deepin

Added by BLottman on Sat, 29 Jan 2022 06:48:33 +0200