This article mainly introduces you to the detailed steps of installing MySql 5.7.21 in Linux. The article introduces it in great detail through sample code. It has certain reference learning value for everyone's study or work. I hope it can help everyone. .
Preface
The most widely used database in Linux is MySQL. This article will give you a detailed introduction to the steps of installing MySql 5.7.21 on Linux. The steps are introduced in great detail. It has certain reference and learning value for everyone's study or work. I won't say much below, let's take a look at the detailed introduction.
1: Go to the mysql official website to download the latest mysql package mysql-5.7.21-linux-glibc2.12-x86_64
Official download address: https://dev.mysql.com/downloads /mysql/
Two: Unzip the mysql compressed package in linux /usr/local/ and rename it to mysql
cd /usr/local/ tar -xzvf mysql压缩包名
Third: Create user group mysql, create user mysql and add it to the user group mysql, and grant read and write permissions
groupadd mysql --Create mysql user group group
useradd -r -g mysql mysql --Create mysql user and add it to mysql user group
chown -R mysql mysql/ --Assign the mysql directory access permissions to the myql user
chgrp -R mysql mysql/ --Change the user group of the mysql directory to belong to the mysql group
Note:
chmod command
is used to change the access permissions of files or directories. It is used by users to control access permissions to files or directories.
chgrp command
Change the group to which a file or directory belongs.
-R processes all files in the specified directory and its subdirectories
Four: Create the configuration file, save and exit
vim /etc/my.cnf #复制以下内容 [client] port = 3306 socket = /tmp/mysql.sock [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid #不区分大小写 lower_case_table_names = 1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_pISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION max_connections=5000 default-time_zone = '+8:00'
Five: Initialize the database
#先安装一下这个东东,要不然初始化有可能会报错 yum install libaio #手动编辑一下日志文件,什么也不用写,直接保存退出 cd /var/log/ vim mysqld.log :wq chmod 777 mysqld.log chown 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
Six: Check the initial password
cat /var/log/mysqld.log
The last line: root@localhost: Here is the initial password
Seven: Start the service, enter mysql, change the initial password, and run the remote connection
#如果提示必须要修改密码才可以进行操作的话则执行下面操作 set password=password('新密码'); flush privileges; UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root'); #然后执行如下操作开启mysql服务,以及设置相关权限 cd /var/run/ mkdir mysqld chmod 777 mysqld cd mysqld vim mysqld.pid chmod 777 mysqld.pid chown mysql:mysql mysqld.pid /usr/local/mysql/support-files/mysql.server start /usr/local/mysql/bin/mysql -uroot -p 你在上面看到的初始密码 # 以下是进入数据库之后的sql语句 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', `Trigger_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;
Eight: Automatically start at boot
cd /usr/local/mysql/support-files cp mysql.server /etc/init.d/mysqld chkconfig --add mysqld
Nine: Use the service mysqld command to start/stop the service
su - mysql service mysqld start/stop/restart 远程用户建立 grant all privileges on *.* to '新用户名'@'%' identified by '新密码'; flush privileges; 添加系统路径 vim /etc/profile export PATH=/usr/local/mysql/bin:$PATH source /etc/profile
Use navicat to enter the user password to connect to mysql successfully!
Related recommendations:
Teach you how to install Nginx server in Linux
Centos7.3 install mysql5.7.18 rpm Tutorial
Detailed explanation of Linux using binary method to install mysql
The above is the detailed content of Detailed steps to install MySql5.7.21 in Linux. For more information, please follow other related articles on the PHP Chinese website!