Install MySql 5.7.21 in Linux.
Preface
MySQL is the most widely used database in Linux. This article will introduce the steps for installing MySql 5.7.21 in Linux, it has some reference and learning value for everyone's learning or work. I will not talk much about it below. Let's take a look at the detailed introduction.
A: To the mysql official website to download the latest mysql package mysql-5.7.21-linux-glibc2.12-x86_64
Https://dev.mysql.com/downloads/mysql/
2. decompress the mysql package in linux/usr/local/and change it to mysql.
Cd/usr/local/tar-xzvf mysql compressed package name
3. Create a user group mysql, create a user mysql, add it to the user group mysql, and grant read and write permissions.
Groupadd mysql -- create a mysql user group
Useradd-r-g mysql -- create a mysql user and add it to the mysql user group
Chown-R mysql/-- Grant the mysql directory access permission to the myql user
Chgrp-R mysql/-- the user group that changes the mysql directory belongs to the mysql group.
Note:
Chmod command
Used to change the access permissions of files or directories. You can use it to control access to files or directories.
Chgrp command
Change the group to which the file or directory belongs.
-R processes the specified directory and all files in its subdirectories.
4. Create a configuration file and save and exit
Vim/etc/my. cnf # copy the following content [client] port = 3306 socket =/tmp/mysql. sock [mysqld] character_set_server = utf8init_connect = 'set NAMES utf8' basedir =/usr/local/mysqldatadir =/usr/local/mysql/datasocket =/tmp/mysql. socklog-error =/var/log/mysqld. logpid-file =/var/run/mysqld. pid # case-insensitive lower_case_table_names = 1sql_mode = STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, region, NO_AUTO_CREATE_USER, region = 5000default-time_zone = '+ 8:00'
V. initialize the database
# Install this plug-in first, or the initialization may report an error in yum install libaio # manually edit the log file without writing anything, and directly save and exit cd/var/log/vim mysqld. log: wqchmod 777 mysqld. logchown mysql: mysql mysqld. log/usr/local/mysql/bin/mysqld -- initialize -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- lc_messages_dir = /usr/local/mysql/share -- lc_messages = en_US
6. view the initial password
cat /var/log/mysqld.log
Last line: root @ localhost: the initial password.
7. Start the service, enter mysql, change the initial password, and run remote connection.
# If you are prompted that you must change the password to perform the operation, perform the following operations: set password = password ('new password'); flush privileges; UPDATE 'mysql '. 'user' SET 'host' = '%', 'user' = 'root' WHERE ('host' = 'localhost') AND ('user' = 'root '); # Then, run the following operations to enable the mysql service and set the related permissions cd/var/run/mkdir mysqldchmod 777 mysqldcd mysqldvim mysqld. pidchmod 777 mysqld. pidchown mysql: mysql mysqld. pid/usr/local/mysql/support-files/mysql. server start/usr/local/mysql/bin/mysql-uroot-p the initial password you saw above # The following is the SQL statement after entering the database use mysql; UPDATE 'mysql '. 'user' SET 'host' = '%', 'user' = 'root', 'select _ priv' = 'y', 'insert _ priv' = 'y ', 'Update _ priv' = 'y', 'delete _ priv' = 'y', 'create _ priv' = 'y', 'drop _ priv' = 'y ', 'reload _ priv' = 'y', 'shutdown _ priv' = 'y', 'process _ priv' = 'y', 'file _ priv' = 'y ', 'Grant _ priv' = 'y', 'references _ priv' = 'y', 'index _ priv' = 'y', 'alter _ priv' = 'y ', 'Show _ db_priv '= 'y', 'Super _ priv' = 'y', 'create _ tmp_table_priv '= 'y', 'lock _ tables_priv' = 'y ', 'execute _ priv' = 'y', 'repl _ slave_priv' = 'y', 'repl _ client_priv '= 'y', 'create _ view_priv' = 'y ', 'Show _ view_priv '= 'y', 'create _ routine_priv' = 'y', 'alter _ routine_priv '= 'y', 'create _ user_priv' = 'y ', 'event _ priv' = 'y', 'triggers _ priv' = 'y', 'create _ tablespace_priv '= 'y', 'ssl _ type' = '', 'ssl _ cipher '= '', 'x509 _ issuer' ='', 'x509 _ subject '= '', 'max _ questions' = '0 ', 'max _ updates' = '0', 'max _ connections '= '0', 'max _ user_connections' = '0', 'plugin' = 'mysql _ native_password ', 'authentication _ string' = '* 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', 'password _ expired' = 'n', 'password _ last_changed '= '2017-11-20 12:41:07 ', 'password _ lifetime' = NULL, 'account _ locked' = 'n' WHERE ('user' = 'root'); flush privileges;
8. Automatic Start upon startup
cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysqldchkconfig --add mysqld
9. Run the service mysqld command to start or stop the service.
Su-mysqlservice mysqld start/stop/restart remote user creates grant all privileges on *. * to 'new Username '@' % 'identified by 'new password'; flush privileges; Add the system PATH vim/etc/profileexport PATH =/usr/local/mysql/bin: $ PATHsource/etc/profile
Using navicat to enter the user password to connect to mysql is successful!
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.