MySQL installation and basic configuration

1.1 MySQL installation and basic configuration (centos 7.3)

  Installation Reference URL: https://www.cnblogs.com/jorzy/p/8455519.html

  1, to see whether the system has been installed MySQL service: Here are two ways

      rpm -qa | grep mysql

      yum list installed | grep mysql

  2, if installed MySQL delete its dependencies

       yum -y remove mysql-libs.x86_64

  3, download mysql57-community-release-el7-8.noarch.rpm source of YUM

       wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

  4, the installation mysql57-community-release-el7-8.noarch.rpm

      rpm -ivh mysql57-community-release-el7-8.noarch.rpm     

      After installation, give the following two packages:

      mysql-community.repo
      mysql-community-source.repo

  5, the installation MySQL, prompted it, in the end all the way to Y

      yum install mysql-server 

  6, required to install mysql libraries and include files

      yum -y install mysql-devel 

  7, to obtain the initial password mysql

      service mysqld start
      grep "password" /var/log/mysqld.log

  8, mysql management commonly used commands

      systemctl status mysqld
      systemctl start mysqld
      systemctl stop mysqld

  9, boot

      systemctl enable mysqld
      systemctl daemon-reload

  10, Mysql After successful installation, the default root user password is empty, you can log in directly

      -p-uroot-MySQL
      mysqladmin -u root password "1" # root user to configure password: 1
      MySQL-uroot--p1 # After configuring the password must login password

1.2 MySQL default character set and modify the engine

  1.  installing MySQL create tables using foreign key failed because the engine does not default

  2.  to MySQL insert Chinese found garbled, because the default character set does not

      show variables like 'character%'; # View MySQL default character set

  3.  The solution is to modify the MySQL configuration file  vim /etc/my.cnf

/etc/my.cnf vim         # following content is to add their own content

[mysqld]
default-storage-engine=INNODB
default_character_set=utf8
character_set_server=utf8

[mysqld_safe]
default-character-set = utf8

[client]
default-character-set = utf8
 
[mysql.server]
default-character-set = utf8
 
[mysql]
default-character-set = utf8
vim /etc/my.cnf

  4. face questions: What is your database storage engine used? The difference is?

      1. Common are MyISAM and InnoDB.
      2.  InnoDB : support foreign key constraints, support the transaction. The index is processed individually, without reference to an index.
      3.  MyISAM : does not support foreign key constraints, it does not support transactions, when large quantities of data import, it will be inserted into the side edge data indexing.
                           So in order to improve the efficiency, you should disable the index, the index opened after a full import

1.3 MySQL create user and authorization

  1. Create a user

    1. command  :  CREATE USER 'username'@'host' IDENTIFIED BY 'password';

        1, username: username you will create
        2, host: Specifies that the user can log on which host, if it is locally available to the user localhost, if you want the user can log in from any remote host, you can use wildcards%
        3, password : the user's login password, the password can be empty, if empty then the user can log in without a password server

    2, an example

        . 1, the CREATE the USER ' tom ' @ ' localhost ' the IDENTIFIED BY '123456'; # tom allowed to log in from localhost
        2, the CREATE the USER ' jack ' @ ' 1.1.1.100 ' the IDENTIFIED BY '123456'; # jack allows the host from 1.1.1.100 Log
        . 3, the CREATE the USER ' fly ' @ ' % ' the IDENTIFIED BY '123456'; # allowed to log in from any host fly

        4, mysql -h 1.1.1.3 -P 3306 -u jack -p123456 # jack login from MySQL 1.1.1.100

        5, update mysql.user set authentication_string = PASSWORD ( 'Chnsys @ 2016') where user = 'opwf'; # change password

  2. Authorization

    1. 命令 : GRANT privileges ON databasename.tablename TO 'username'@'host'

        1, privileges: a user's operation authority, such as SELECT, INSERT, UPDATE, etc., if you want to grant permissions to use ALL
        2, DatabaseName: database name
        3, tablename: table name, if you want to grant the user for all databases and tables * available respective operating authority is represented as *. *

    2. Examples

        1, GRANT  the SELECTINSERT  ON  testdb . Student  the TO 'tom' @ '%'; # authorized tom inquiries and insert permission on testdb database
        2, GRANT  ALL  ON  * . *  The TO ' jack ' @ ' % '; # authorization jack for all databases, all tables all permissions

  3, viewing permissions 

        1, show grants for 'tom' @ 'localhost'; # View tom user privileges on the host 1.1.1.100

        2, show grants for root; # View the root user privileges

  4, revoke privileges 

        1, REVOKE all ON * * FROM 'tom' @ '%';. # Tom revoke all databases, all tables, all permissions

# 1, create a user 
the Create the User ' MUP ' @ ' % ' IDENTIFIED by ' mup_yiducloud ' ;

# 2, grant a user granted authority to operate mup database mup 
the GRANT the ON mup * the TO ALL. ' Mup ' @ ' % ' ;
flush privileges;
select host,user from mysql.user;

# 3、删除用户
Delete FROM mysql.user Where User='mup' and Host=”localhost”; 
Delete FROM mysql.user Where User='mup'; 

# 4、修改root密码
update mysql.user set authentication_string=password('mysqlRootPwd') where user='root' and Host = 'localhost';
mysql create authorized common actions

1.4 mysql common error 

  1、ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

# MySQL -u root -p # Log 
# MySQL> the SET, Ltd. Free Join validate_password_policy = 0; # password strength to the lowest level 
# MySQL> the SET, Ltd. Free Join validate_password_length = 4; # password allows a minimum length of 4 
# MySQL> flush privileges; # update authorization table, take effect

  2、ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'bsp'

      Reference Address: https://blog.csdn.net/slovyz/article/details/52182283

    1. The reason given 

        1. In fact, it should be said that basically my.cnf file because there are skip-name-resolve this parameter causes parameter which can not be resolved hostname Login or otherwise;
        2. So log in to any user, do not take the time to match the root @ 'localhost', or 127.0.0.1 or :: 1 but he kept walking root @ '%';

    2, the solution

# 1, check to see if the root user in each mode has grant permission 
MySQL> the SELECT Grant_priv from the User the WHERE Host = ' 127.0.0.1 ' ;
 + ------------ +
| Grant_priv |
+------------+
| N          |
+------------+
1 row in set (0.00 sec)

mysql> select Grant_priv from user where Host='localhost';
+------------+
| Grant_priv |
+------------+
| N          |
+------------+
1 row in set (0.01 sec)


# 2, without restarting the MySQL service, only need to add -h parameter when logging in 
(A) / usr / local / MySQL / bin / MySQL-uroot--p123456 -. H localhost
(b). /usr/local/mysql/bin/mysql -uroot -p123456 -h127.0.0.1

# 3, have allowed to grant permission to change user rights 
MySQL> Update User SET Grant_priv = ' the Y ' WHERE the Host = ' 127.0.0.1 ' ;
mysql> update user set Grant_priv='Y' where Host='localhost';
mysql> flush privileges;

# 4, exit again with the root login, and then the operation
Solution

  3、ERROR 1045 (28000): Access denied for user 'opwf'@'localhost' (using password: YES) 

      Reference Address: https://www.cnblogs.com/bk7788/p/6388562.html

    1. The reason given 

        1. The general idea is that you have a user account name is blank, mysql will first match it, and then you have the wrong password prompt, delete the anonymous user, and then execute FLUSH PRIVILEGES;

        DELETE FROM mysql.user WHERE user='';

        FLUSH PRIVILEGES

 

Guess you like

Origin www.cnblogs.com/jiaxinzhu/p/12466755.html