MySQL database Introduction
The most famous, the most widely used open-source database software
- the first belonging to the Swedish company MySQL AB
- In January 2008, MySQL AB was acquired by SUN
- April 2009, SUN acquired by Oracle
A new open source branch MariaDB
- To cope with the risks may be closed-source MySQL birth
- developed by leading author Widenius MySQL
- maintaining maximum compatibility with MySQL
MySQL features and applications
main feature
- For small and medium-scale, relational database systems
- Support for multiple operating systems Linux / Unix, Windows, etc.
- written in C and C ++, portability
- Support Python / JAVA / Perl / PHP and other languages via the API
Application Environment
-LAMP platform, in combination with the Apache HTTP Server
-LNMP platform, combined with Nginx
Mysql installation
Ready to work
- Stop mariadb Service
- Delete files /etc/my.cnf
-delete data
- uninstall packages
[root@proxy ~]# systemctl stop mariadb [root@proxy ~]# rm -rf /etc/my.cnf [root@proxy ~]# rm -rf /var/lib/mysql/* [root@proxy ~]# rpm -e --nodeps mariadb-server mariadb Warning: /var/log/mariadb/mariadb.log saved as /var/log/mariadb/mariadb.log.rpmsave
Mounting at least a server, client, share * package
- Use -U upgrade installation, you can replace conflicting files
- recommended devel installed to support other software
[root@proxy ~]# yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes [root@proxy ~]# tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar [root@proxy ~]# rm -f mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm [root@proxy ~]# rpm -Uvh mysql-community-*.rpm
Start the MySQL database service
- Service script /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# systemctl start mysqld [root@localhost ~]# systemctl enable mysqld [root@localhost ~]# systemctl status mysqld
MySQL initial configuration
The default database account management
-root, allow access from localhost
- for the first time login password is randomly generated during installation
- stored in the error log file
[root@proxy ~]# grep 'temporary password' /var/log/mysqld.log 2019-06-24T15:19:18.303935Z 1 [Note] A temporary password is generated for root@localhost: zzXdihIzU4-_ [root@proxy ~]# mysql -uroot -p'zzXdihIzU4-_'
mysql> set global validate_password_policy = 0; // only authentication length Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length = 6; // change the password length, the default is 8 characters Query OK, 0 rows affected (0.00 sec) mysql> alter user user () identified by "123456"; // Change My Password Query OK, 0 rows affected (0.00 sec)
Client server connection using the command
[root@proxy ~]# mysql -uroot -p123456 mysql: [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 3Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
MySQL service-related parameters
file |
Explanation |
/etc/my.cnf | The main configuration file |
/ Var / lib / mysql | Database directory |
The default port number | 3306 |
Process ID | mysqld |
Transfer Protocol | TCP |
Process owner | mysql |
Process belongs to the group | mysql |
The basic database management
Common SQL operation instruction
-DDL data definition language (create, alter, drop)
-DML data definition language (insert, update, delete)
-DCL data definition language (grant, revoke)
-DTL data definition language (commit, rollback, savepoint)
Library management commands
-show databases; // display existing library
-Use library name; // switch library
-Select database (); // display library is currently located
-Create database library name; // Create a new library
-Show tables; // display existing library
-Drop database library name; // delete library
Table Management Command
-Desc table name; // View table structure
-Select * from table name; // Display Record
-Drop table table name; // Delete table
Records Management Command
-Select * from table name; // Display Record
-Insert into table values (value list); // table record inserted
-Update table set field = value; // modify records table
-Delete from table name; // delete table records
Time Functions
Types of | use |
now() | Gets the current system date and time |
year() | Dynamic get the system date and time of execution |
sleep() | Sleep N seconds |
curdate() | Gets the current system date |
CURTIME () | Gets the current system time |
month() | Gets a specified time in the month |
date() | Gets the date specified in the time |
time() | The acquisition time for the specified time |
No need to databases, tables, can be called directly
- Use the SELECT command output function results
mysql> select now(),sysdate(),curdate(); +---------------------+---------------------+------------+ | now() | sysdate() | curdate() | +---------------------+---------------------+------------+ | 2019-06-25 22:10:45 | 2019-06-25 22:10:45 | 2019-06-25 | +---------------------+---------------------+------------+ 1 row in set (0.00 sec)
mysql> select date(now()),time(now()); +-------------+-------------+ | date(now()) | time(now()) | +-------------+-------------+ | 2019-06-25 | 22:11:41 | +-------------+-------------+ 1 row in set (0.00 sec)