MySQL Basic simple operation

Source: Internet
Author: User
Tags mysql backup percona percona server phpmyadmin docker run

MySQL Basic simple operation

Learn to install Docker , then use it. (/Funny Face)
Before want to learn Mysql (Windows configuration is really troublesome), learned to Docker be convenient, directly use to Docker create a service is not Mysql flattered. To create a container, take a look at the Nginx creation process of sharing 04.
First check the local mirror.

[[email protected] ~]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

There is no Mysql image, then I will first pull a Mysql mirror.
Search Mysql for the following image first.

[[email protected] ~]# Docker search Mysqlindex NAME                                                  DESCRIPTION STARS official Automateddocker.io docker.io/mysql   MySQL is a widely used, Open-source Relati ... 6527 [Ok]docker.io docker.io/mariadb mariadb is a community-develope   D Fork of M ... 2061 [Ok]docker.io docker.io/mysql/mysql-server Optimized MySQL server docker i Mages.   Crea ... 479 [Ok]docker.io Docker.io/percona Percona Server is a   Fork of the MySQL rela ... 344 [Ok]docker.io docker.io/zabbix/zabbix-server-mysql Zabbix server with MySQL Databa SE support 106 [Ok]docker.io Docker.io/hypriot/rpi-mysql RPI -Compatible Docker Image with Mysql 89docker.io docker.io/centurylink/mysql Image containing MySQL.   Optimized to be Li ... [Ok]docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend Base   D on Nginx web-server ... [Ok]docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-                                            phpmyadmin-mysql-5 [Ok]docker.io Docker.io/tutum/mysql   Base Docker image to run a MySQL database ...                   32docker.io docker.io/centos/mysql-57-centos7 mysql 5.7 SQL database server 31docker.io docker.io/mysql/mysql-cluster experimental MySQL cluster docker imag Es.   ... 30docker.io docker.io/schickling/mysql-backup-s3 backup MySQL to S3 (supports periodic back. ..  [Ok]docker.io docker.io/bitnami/mysql Bitnami MySQL Dock                              Er Image [Ok]docker.io docker.io/zabbix/zabbix-proxy-mysql                                       Zabbix Proxy with MySQL database support [Ok]docker.io Docker.io/linuxserver/mysql   A Mysql container, brought to your by Linux ...                   14docker.io docker.io/centos/mysql-56-centos7 mysql 5.6 SQL database server 8docker.io Docker.io/openshift/mysql-55-centos7 deprecated:a Centos7 based MySQL v5.5   Ima... 6docker.io Docker.io/circleci/mysql MySQL is a widely used, Open-source Relati.   .                5docker.io docker.io/dsteinkopf/backup-all-mysql Backup All DBs in a MySQL server 4 [Ok]docker.io Docker. io/mysql/mysql-router MySQL router provides transparent routing ... 2docker.io docker.io/openzipkin/zipkin-mysql Mirror of Https://quay.io/repository/openz.   .                1docker.io DOCKER.IO/ANSIBLEPLAYBOOKBUNDLE/MYSQL-APB an APB which deploys RHSCL MySQL  0 [Ok]docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of Cf-mysql-release 0docker.io Docker.io/cloudposse/mysql improved ' my   SQL ' service with support for ... 0 [OK]

Then pull the image to the local, of course, the first official image.

[[email protected] ~]# docker pull docker.io/mysqlUsing default tag: latestTrying to pull repository docker.io/library/mysql ...latest: Pulling from docker.io/library/mysql683abbb4ea60: Pull complete0550d17aeefa: Pull complete7e26605ddd77: Pull complete9882737bd15f: Pull complete999c06ab75f6: Pull completec71d695f9937: Pull completec38f847c1491: Pull complete5e0cb05a8fc3: Pull completec89e3e373fca: Pull completefa39a2c9922d: Pull completeb293d9c897c4: Pull complete3dc061869740: Pull completeDigest: sha256:43ed4f8c9d1695e97a39cdfe9475af9096e3723cfb79d820d8da00d61a277a85Status: Downloaded newer image for docker.io/mysql:latest

Pull succeeds, now start creating the Mysql container.

[[email protected] ~]# docker run -itd --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=000000 docker.io/mysql30d60b852cf57c5f4e7df36846b10149387bb2b736cecb11f12a2d64a3bdbf43

into the container.

[[email protected] ~]# docker exec -it mysql /bin/bash[email protected]:/#

Connect to the database.

[email protected]:/# mysql -uroot -p000000mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.11 MySQL Community Server - GPLCopyright (c) 2000, 2018, 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>

Connect to the database successfully!
Learn to view the database first.

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.01 sec)

The database is then created.

mysql> create database gubeiqing;Query OK, 1 row affected (0.02 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| gubeiqing          || information_schema || mysql              || performance_schema || sys                |+--------------------+5 rows in set (0.00 sec)

Then use the database I just created gubeiqing .

mysql> use gubeiqing;Database changed

After entering this database, take a look at what tables are available.

mysql> show tables;Empty set (0.00 sec)

The data table is empty at this time, and then the data table is created.

mysql> create table gubeiqing1(name varchar(20) not null , age varchar(20) not null);Query OK, 0 rows affected (0.08 sec)

The general statement syntax for building a table is: CREATE TABLE table_name (column_name column_type); .
Now let's look at what the data table looks like.

mysql> desc gubeiqing1;+-------+-------------+------+-----+---------+-------+| Field | Type        | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+-------+| name  | varchar(20) | NO   |     | NULL    |       || age   | varchar(20) | NO   |     | NULL    |       |+-------+-------------+------+-----+---------+-------+2 rows in set (0.00 sec)

You can see gubeiqing1 that the data table now has two columns. But there is no data, so now add the data to the table.

mysql> insert into gubeiqing1 (name,age) values ('gbq',21);Query OK, 1 row affected (0.04 sec)

If the data you are adding is a character type, you must use either single or double quotation marks.
Now look at all the contents of this table.

We can see that the data has been added by us.

mysql> select * from gubeiqing1;+------+-----+| name | age |+------+-----+| gbq  | 21  |+------+-----+1 row in set (0.00 sec)

The simple syntax for query statements is: SELECT column_name,column_name FROM table_name .

Insert a few more (you can insert without specifying the column name, but you need to know the order in which you inserted the data).

mysql> insert into gubeiqing1 values ('zhangsan',20);Query OK, 1 row affected (0.05 sec)mysql> insert into gubeiqing1 values ('lisi',19);Query OK, 1 row affected (0.03 sec)

Take a look.

mysql> select * from gubeiqing1;+----------+-----+| name     | age |+----------+-----+| gbq      | 21  || zhangsan | 20  || lisi     | 19  |+----------+-----+3 rows in set (0.00 sec)

Then learn to change the data.
Now I will lisi age change the field from 19 the 22 .

mysql> update gubeiqing1 set age=22 where name='lisi';Query OK, 1 row affected (0.04 sec)Rows matched: 1  Changed: 1  Warnings: 0

The basic simple syntax for changing data is: UPDATE table_name SET column_name1=values1,column_name2=values2 [WHERE 条件表达式] .

Check the data sheet again.

mysql> select * from gubeiqing1;+----------+-----+| name     | age |+----------+-----+| gbq      | 21  || zhangsan | 20  || lisi     | 22  |+----------+-----+3 rows in set (0.00 sec)

The fields you can see lisi age have been changed.
Database basic additions and deletions to check, has seen three, and then look at the deletion.
zhangsanremove this data from the data table.

mysql> delete from gubeiqing1 where name='zhangsan';Query OK, 1 row affected (0.39 sec)mysql> select * from gubeiqing1;+------+-----+| name | age |+------+-----+| gbq  | 21  || lisi | 22  |+------+-----+2 rows in set (0.00 sec)

Then delete the table, and finally delete the library.

mysql> drop table gubeiqing1;Query OK, 0 rows affected (0.13 sec)mysql> show tables;Empty set (0.00 sec)mysql> drop database gubeiqing;Query OK, 0 rows affected (0.09 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)

MySQL Basic simple operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.