01, Reference Guide : open under CentOS mysql remote connection, remote database management , CentOS install and set up MariaDB , MySQL management , centos7 installation Mariadb
02, install MariaDB , rely on default installation mariadb, one server and one client.
[root@epimetheus ~]# yum install mariadb-server -y
03, configure MariaDB
01) After installation is first necessary to MariaDB service is turned on and set to boot
[root @ Epimetheus ~ ] # # systemctl Start MariaDB open service
[root @ Epimetheus ~] # # systemctl enable MariaDB is set to boot from the start Services
02) need to first install the configuration database
[root @ Epimetheus ~] # mysql_secure_installation
the Enter Current password for root (the Enter for none): # Enter the root password database super administrator (note not the system root password), for the first time has not yet set a password to enter directly Enter Set password root ? [the Y-/ the n-] # set a password, the y- new password: # new password Re - the enter new new password: # enter the password again the remove the users anonymous [the Y-/? the n-] # remove anonymous users, the y- Disallow root the Login remotely? [Y / n] # refused root remote login, n, regardless of the y-/ the n-, will refuse to root remote login the Remove test database and Access to IT [the Y-/? the n-] # delete the test database, y: delete. n: Do not delete, the database will be a test database, generally does not require Reload the Tables Privilege now [the Y-/ the n-] # reload the privileges table, y?. Or maybe restart the service
03) tests the ability to log in successfully, appears MariaDB [(none)]> says have been able to log in normally use the database MariaDB
[root@epimetheus ~]# mysql -u root -p
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
04, links mariadb remote database , the default is to deny root remote login.
1) system firewall
① can choose to turn off the firewall
[root@epimetheus ~]# systemctl stop firewalld
② without turning off the firewall, allowing a link to a foreign port. Steps to open port 3306, restart the firewall
[Epimetheus the root @ ~] # --query Firewall-Port-cmd = 3306 / TCP # 3306 to see whether to open ports NO [Epimetheus the root @ ~] # = Firewall-cmd --zone public --add-Port = 3306 / TCP - Permanent # 3306 open ports Success [root @ Epimetheus ~] # firewall-cmd - reload # restart firewall Success [root @ Epimetheus ~] # firewall-cmd --query-port = 3306 / tcp # 3306 to see whether to open ports yes
③ When configured in Ali cloud CentOS, has always been unable to remotely access mariadb, eventually found Ali cloud console, there is a layer "firewall", that is, instances security groups.
2) configure access in mysql
① first check mysql database user table
[Epimetheus the root @ ~] -u # MySQL the root - P # to enter the database via local link MariaDB [(none)] > use MySQL; MariaDB [MySQL] > SELECT Host, User from User; + ------- + ------ + ---- | Host | the User | + ----------- + ------ + | 127.0 . 0.1 | root | | :: 1 | root | | Epimetheus | root | + ----------- + ------ + rows in the SET ( 0.00 sec)
② will be changed to "%" equal to the host name field, my host name epimetheus,
MariaDB [mysql]> update user set host='%' where host='epimetheus'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [mysql]> select host, user from user; +-----------+------+ | host | user | +-----------+------+ | % | root | | 127.0.0.1 | root | | localhost | root | +-----------+------+ rows in set (0.00 sec)
③ refresh authority table, or restart mariadb service, it can be a second election
MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) [root@epimetheus ~]# systemctl restart mariadb
Note: refresh authority table is in the database, restart the service is outside the command line
05, may be used to when using the mysql command
01) command in the system console
[root @ Epimetheus ~] # MySQL -h 192.168 . 1.100 -P 3306 -u root - the p-# This is the telnet command, using the account number and password to access the database [root @ Epimetheus ~] # # MySQL -u root -p this this machine is the command log, using the root account and password to access the database
02) In the mysql command line, you can enter and execute the sql statement
--创建表 CREATE TABLE user_info (userId INTEGER PRIMARY KEY AUTOINCREMENT, userName TEXT, userAge INTEGER); CREATE TABLE IF NOT EXISTS user_info (userId INTEGER PRIMARY KEY AUTOINCREMENT, userName TEXT, userAge INTEGER); CREATE TABLE user_info (userId INTEGER, userName TEXT, userAge INTEGER, PRIMARY KEY(userId, userName)); --销毁表 DROP TABLE user_info; - modify a table, an increase of the ALTER TABLE TAB_NAME the ADD the COLUMN col_name TEXT ; - modify the table, modify table, Note: The new name will be put on the table in double quotes the ALTER TABLE TAB_NAME RENAME the TO new_tab_name; - delete item the DELETE the FROM USER_INFO the WHERE the userName = ' Saber ' ; - Add item the INSERT the INTO USER_INFO (the userName, userAge) the VALUES ( ' Saber ' , 18 is ); INSERT INTO user_info(userName, userAge) VALUES('saber', 18), ('baserker', 22); INSERT INTO mo_personmap (personid, belongid) SELECT b.id, b.departid FROM mo_person b; --修改项 UPDATE user_info SET userAge=16 WHERE userName='saber'; --查询项 SELECT *FROM user_info;
03) can also perform their own program mysql command, for example:
. MySQL> Grant All privileges ON * * to ' root ' @ ' % ' IDENTIFIED by ' mypassword ' with Grant the Option; # Set account root may be exercised any ip All rights MySQL > flush privileges; # the permission settings to take effect MySQL> Show databases; # display all existing database mysql > use MyDatabase; # select the specified database mysql> show the tables; # display all the tables mysql > show the Columns from MyTable; # display table structure design mysql > exit; exit # mysql