Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Mysql 5.7in Linux 7

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "Linux 7 how to install Mysql 5.7", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Linux 7 how to install Mysql 5.7" this article.

Install MySql 5.7 in Oracle Linux 7.1. Mysql installation location: / mysqlsoft/mysql, database file data location: / mysqldata/mysql.

1. First download the installation media

Mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

two。 Create a folder mysqlsoft and database data file / mysqldata/mysql under the root directory

[root@cs2 /] # mkdir-p / mysqlsoft [root@cs2 /] # mkdir-p / mysqldata/mysql [root@cs2 /] # ls-lrt / mysqldata/total 0drwxr-xr-x 2 root root 6 May 31 11:58 mysql

3. Upload the media mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz to the / mysqlsoft directory and extract it

[root@cs2 /] # cd mysqlsoft [root@cs2 mysqlsoft] # ls-lrttotal 628704 RWML-1 root root 643790848 Apr 20 2018 mysql-5.7.22-linux-glibc2.12-x86_ 64.tar.gz [root @ cs2 mysqlsoft] # tar-zxvf mysql-5.7.22-linux-glibc2.12-x86_ 64.tar.gz [root @ cs2 mysqlsoft] # ls-lrttotal 628704 Mustang RWML-1 root root 643790848 Apr 20 2018 mysql-5.7 .22-linux-glibc2.12-x86_64.tar.gzdrwxr-xr-x 9 root root 120 May 31 12:11 mysql-5.7.22-linux-glibc2.12-x86_64

It is recommended that you generally do not change the default file name and do it through a soft connection.

[root@cs2 mysqlsoft] # mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql [root@cs2 mysqlsoft] # ls-lrttotal 628704 mysql-5.7.22-linux-glibc2.12-x86_64lrwxrwxrwx-1 root root 643790848 Apr 20 2018 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gzdrwxr-xr-x 9 root root 120 May 31 13:28 mysql-5.7.22-linux-glibc2.12-x86_64lrwxrwxrwx 1 root root 35 May 31 13:33 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64 [root@cs2 mysqlsoft] # cd mysql [root@cs2 mysql] # lsbin COPYING docs include lib man README share support-files

4. Create mysql users and user groups

[root@cs2 mysql] # groupadd mysql [root@cs2 mysql] # useradd-r-g mysql-s / bin/false mysql

Because the user is used only for ownership purposes, not for login purposes, the useradd command uses the-r and-s / bin/false options to create a user that does not have permission to log on to the server host.

5. Modify / mysqlsoft/mysql and / mysqldata/mysql directory permissions

[root@cs2 /] # chown-R mysql:mysql / mysqlsoft/mysql [root@cs2 /] # chown-R mysql:mysql / mysqldata/mysql [root@cs2 /] # chmod-R 775 / mysqlsoft/mysql [root@cs2 /] # chmod-R 775 / mysqldata/mysql

6. MySQL is dependent on the libaio library. If the libaio library is not installed, data directory initialization and subsequent database service startup will fail. Install the libaio library to perform the following operations:

Query whether the libaio library is installed

[root@cs2 local] # yum search libaioLoaded plugins: langpacksRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast= Development files for Linux-native asynchronous S matched: libaio = libaio.i686: Linux-native asynchronous I access librarylibaio.x86_64 O access librarylibaio.x86_64: Linux-native asynchronous I Development files for Linux-native asynchronous O access librarylibaio-devel.i686: Development files for Linux-native asynchronous I access Name and summary matches only O accesslibaio-devel.x86_64: Development files for Linux-native asynchronous O access Name and summary matches only, use "search all" for everything.

If it is not installed, you can execute the following command to install it

[root@cs2 local] # yum install libaioLoaded plugins: langpacksRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast file:///run/media/jy/OL-7.1%20Server.x86_64/repodata/repomd.xml: [Errno 14] curl#37-"Couldn't open file / run/media/jy/OL-7.1%20Server.x86_64/repodata/repomd.xml" Trying other mirror.Package libaio-0.3.109-12.el7.x86_64 already installed and latest versionNothing to do

7. Configure mysql parameters

Just set a few simple mysql running parameters

[root@cs2 ~] # vi / mysqlsoft/mysql/my.cnf [mysqld] basedir=/mysqlsoft/mysqldatadir=/mysqldata/mysqlbind-address=0.0.0.0user=mysqlport=3306log-error=/mysqldata/mysql/mysql.errpid-file=/mysqldata/mysql/mysqld.pidsocket = / mysqldata/mysql/mysql.sockcharacter-set-server=utf8default-storage-engine=INNODBexplicit_defaults_for_timestamp = true "/ mysqlsoft/mysql/my.cnf" [New] 67L, 1642C written

Note: log-error must be configured, because if mysql starts up incorrectly, the cause of the error can be found in the log file. Second, bind-address is configured with 0.0.0.0 to listen for all connections. Also, the path to the mysql.sock file specified by the socket parameter is best set to / tmp/mysql.sock, because the default location of the unix socket file is in the / tmp directory.

8. Initialize mysql

[root@cs2 /] # cd / mysqlsoft/mysql/bin [root@cs2 bin] #. / mysqld-- user=mysql-- defaults-file=/mysqlsoft/mysql/my.cnf-- basedir=/mysqlsoft/mysql-- datadir=/mysqldata/mysql-- initialize [root@cs2 mysql] # cat mysql.err2019-05-31T06:01:50.260643Z 0 [Warning] 'NO_ZERO_DATE',' NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode They will be merged with strict mode in a future release.2019-05-31T06:01:50.260731Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 1002019-05-31T06:01:53.795162Z 0 [Warning] InnoDB: New log files created, LSN=457902019-05-31T06:01:54.049268Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2019-05-31T06:01:54.102171Z 0 [ERROR] unknown variable 'defaults-file=/mysqlsoft/mysql/my.cnf'2019-05-31T06:01:54.102193Z 0 [ERROR] Aborting

Some people on the Internet said that it was a problem of file permissions, and then re-authorized chmod 664 my.cnf but did not solve it. Some people suggested that the order of parameters should be adjusted! Finally, it is effective to adjust the order of the parameters:

[root@cs2 bin] # / mysqld-- defaults-file=/mysqlsoft/mysql/my.cnf-- initialize-- basedir=/mysqlsoft/mysql-- datadir=/mysqldata/mysql-- user=mysql [root@cs2 mysql] # cat mysql.err2019-05-31T06:05:06.362925Z 0 [Warning] 'NO_ZERO_DATE',' NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.2019-05-31T06:05:06.362994Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 1002019-05-31T06:05:09.779913Z 0 [Warning] InnoDB: New log files created, LSN=457902019-05-31T06:05:10.026707Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2019-05-31T06:05:10.094462Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0be6983a-836a-11e9-a341-005056a092af.2019-05-31T06:05:10.109209Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2019-05-31T06:05:10.110107Z 1 [Note] A temporary password is generated for root@localhost: Pm93qnL%-j2019-05-31T06:05:14.966324Z 1 [Warning] 'user' entry' root@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06:05:14.966373Z 1 [Warning] 'user' entry' mysql.session@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06:05:14.966391Z 1 [Warning] 'user' entry' mysql.sys@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06 05Warning 14.966419Z 1 [Warning] 'db' entry' performance_schema mysql.session@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06:05:14.966428Z 1 [Warning] 'db' entry' sys mysql.sys@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06:05:14.966441Z 1 [Warning] 'proxies_priv' entry' @ root@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06: 05user mysql.session@localhost' ignored in 14.966493Z 1 [Warning] 'tables_priv' entry' user mysql.session@localhost' ignored in-- skip-name-resolve mode.2019-05-31T06:05:14.966508Z 1 [Warning] 'tables_priv' entry' sys_config mysql.sys@localhost' ignored in-- skip-name-resolve mode.

The root@localhost of [Note] A temporary password is generated for root@localhost:,; pm93qnL%-j is followed by the temporary password for logging in to the mysql database. The temporary password generated by each installation is different. You can see that the log file did not report an error, and there is a temporary password, indicating that the initialization was successful.

9. If you want the service to be able to deploy automatic support for secure connections, use the mysql_ssl_rsa_setup tool to create default SSL and RSA files

[root@cs2 bin] # / mysql_ssl_rsa_setup-- datadir=/mysqldata/mysqlGenerating a 2048 bit RSA private key....+++. Writing new private key to 'ca-key.pem'-Generating a 2048 bit RSA private key.+++.+++writing new private key to' server-key.pem'-Generating a 2048 bit RSA private key. .. +... + writing new private key to 'client-key.pem'-

9. Start the mysql service

[root@cs2 /] # sh / mysqlsoft/mysql/support-files/mysql.server start/mysqlsoft/mysql/support-files/mysql.server: line 239: my_print_defaults: command not found/mysqlsoft/mysql/support-files/mysql.server: line 259: cd: / usr/local/mysql: No such file or directoryStarting MySQL ERROR! Couldn't find MySQL server (/ usr/local/mysql/bin/mysqld_safe)

The command to start the mysql service will report an error because the configuration file of mysql has not been modified

Modify the Mysql configuration file with the following before modification

If test-z "$basedir" then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin if test-z "$datadir" then datadir=/usr/local/mysql/data fi sbindir=/usr/local/mysql/bin libexecdir=/usr/local/mysql/binelse bindir= "$basedir/bin" if test-z "$datadir" then datadir= "$basedir/data" fi sbindir= "$basedir/sbin" libexecdir= "$basedir/libexec" fi

The modified content is as follows

[root@cs2 ~] # vi / mysqlsoft/mysql/support-files/mysql.serverif test-z "$basedir" then basedir=/mysqlsoft/mysql bindir=/mysqlsoft/mysql/bin if test-z "$datadir" then datadir=/mysqldata/mysql fi sbindir=/mysqlsoft/mysql/bin libexecdir=/mysqlsoft/mysql/binelse bindir= "$basedir/bin" if test-z "$datadir" then datadir= "$basedir/data" fi sbindir= "$basedir/sbin" libexecdir= "$basedir/libexec" fi [root@cs2 ~] # cp / mysqlsoft/mysql / support-files/mysql.server / etc/init.d/mysqld [root@cs2 ~] # chmod 755 / etc/init.d/mysqld

10. Start mysql

[root@cs2 ~] # service mysqld startStarting MySQL.. SUCCESS!

11. Configure environment variables

[root@cs2] # vi / etc/profile# / etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in / etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# / etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.export MYSQL_HOME=/mysqlsoft/mysql/export PATH=$PATH:$MYSQL_HOME/bin

11. Log in to Mysql

After successful initialization, check the initialization password

[root@cs2 ~] # cat / mysqldata/mysql/mysql.err | grep password2019-05-31T06:05:10.110107Z 1 [Note] A temporary password is generated for root@localhost:,; pm93qnL%-j

And enter the password you just copied, but prompt that you cannot connect through the mysql.sock file

[root@cs2 bin] #. / mysqladmin-u root-p passwordEnter password: mysqladmin: connect to server at 'localhost' failederror:' Can't connect to local MySQL server through socket'/ mysqlsoft/mysql/mysql.sock' (2) 'Check that mysqld is running and that the socket:' / mysqlsoft/mysql/mysql.sock' exists!

This is strange, because the socket file path set in the my.cnf file is / mysqldata/mysql/mysql.sock, but the file used by mysql is not generated by the startup service.

[root@cs2 ~] # cat / mysqlsoft/mysql/ my.cnf [mysqld] basedir=/mysqlsoft/mysqldatadir=/mysqldata/mysqlbind-address=0.0.0.0user=mysqlport=3306log-error=/mysqldata/mysql/mysql.errpid-file=/mysqldata/mysql/mysqld.pidsocket = / mysqldata/mysql/mysql.sockcharacter-set-server=utf8default-storage-engine=INNODBexplicit_defaults_for_timestamp = true [root@cs2 mysql] # ls-lrttotal 286896 RWMurray r-1 mysql mysql 134217728 May 31 14:05 ib_logfile1-rw-r -- 1 mysql mysql 56 May 31 14:05 auto.cnfdrwxr-x--- 2 mysql mysql 8192 May 31 14:05 performance_schemadrwxr-x--- 2 mysql mysql 31 14:05 mysqldrwxr-x--- 2 mysql mysql 8192 May 31 14:05 sys-rw- 1 mysql mysql 1679 May 31 14:25 ca-key.pem-rw-r--r-- 1 mysql mysql 1107 May 31 14:25 ca.pem-rw -1 mysql mysql 1679 May 31 14:25 server-key.pem-rw-r--r-- 1 mysql mysql 1107 May 31 14:25 server-cert.pem-rw- 1 mysql mysql 1679 May 31 14:25 client-key.pem-rw-r--r-- 1 mysql mysql 1107 May 31 14:25 client-cert.pem-rw- 1 mysql mysql 1679 May 31 14:25 private_ Key.pem-rw-r--r-- 1 mysql mysql 451 May 31 14:25 public_key.pem-rw-r- 1 mysql mysql 291 May 31 18:05 ib_buffer_pool-rw- 1 mysql mysql 6 May 31 18:08 mysql.sock.locksrwxrwxrwx 1 mysql mysql 0 May 31 18:08 mysql.sock-rw-r- 1 mysql mysql 6 May 31 18:08 Mysqld.pid-rw-r- 1 mysql mysql 101396 May 31 18:08 mysql.err-rw-r- 1 mysql mysql 12582912 May 31 18:08 ibtmp1-rw-r- 1 mysql mysql 12582912 May 31 18:08 ibdata1-rw-r- 1 mysql mysql 134217728 May 31 18:08 ib_logfile0

You can see that the mysql.sock in the / var/lib/mysql directory points to the / mysqlsoft/mysql/mysql.sock file.

[mysql@cs2] $ls-lrt / var/lib/mysql total dosage 110604 RWMY RW Murray. 1 27 27 50331648 October 11 2017 ib_logfile1drwx-. 2 27 27 4096 October 11 2017 performance_schemadrwx-. 2 27 27 4096 October 11 2017 mysql-rw-rw----. 1 27 27 56 October 11 2017 auto.cnf-rw-rw----. 1 27 27 50331648 May 30 18:32 ib_logfile0-rw-rw----. 1 27 27 12582912 May 30 18:32 ibdata1lrwxrwxrwx 1 root root 27 May 31 15:44 mysql.sock-> / mysqlsoft/mysql/mysql.sock

You can log in successfully if you use the-S option to specify the generated mysql.sock file for login

[mysql@cs2 mysql] $mysql-S / mysqldata/mysql/mysql.sock-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 6Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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 > quit

Modify the socket file path to / mysqlsoft/mysql/mysql.sock

[root@cs2 ~] # cat / mysqlsoft/mysql/ my.cnf [mysqld] basedir=/mysqlsoft/mysqldatadir=/mysqldata/mysqlbind-address=0.0.0.0user=mysqlport=3306log-error=/mysqldata/mysql/mysql.errpid-file=/mysqldata/mysql/mysqld.pidsocket = / mysqlsoft/mysql/mysql.sockcharacter-set-server=utf8default-storage-engine=INNODBexplicit_defaults_for_timestamp = true

Restart the mysql service

[root@cs2 ~] # service mysqld stopShutting down MySQL.. SUCCESS! [root@cs2 ~] # service mysqld startStarting MySQL.. SUCCESS! [mysql@cs2 ~] $mysql-u root-p Enter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 4Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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 >

This allows you to log in.

twelve。 Reset root user password

[mysql@cs2] $mysql-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 2Server version: 5.7.22Copyright (c) 2000, 2018, 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 > set password=password ("123456"); Query OK, 0 rows affected, 1 warning (0.00 sec)

13. Set to allow remote login to mysql

If you want to access the database remotely, you only need to change the Host field of the record corresponding to the root account with full permissions to%

Mysql > use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changedmysql > update user set host='%' where user='root';Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql > flush privileges;Query OK, 0 rows affected (0.00 sec) mysql > grant all privileges on *. * to root@'%';Query OK, 0 rows affected (0.00 sec) mysql > flush privileges;Query OK, 0 rows affected (0.00 sec)

Test remote login

-bash-4.2$ mysql-h 10.11.13.19-P 3306-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 4Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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 > use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changedmysql > SELECT DISTINCT CONCAT ('User: [', user,''@'', host,'];) AS USER_HOST FROM user +-- + | USER_HOST | +-+ | User: [root'@'%]; | User: [mysql.session'@'localhost] | | User: [mysql.sys'@'localhost]; | +-- + 3 rows in set (0.05sec) above are all the contents of the article "how to install Mysql 5.7 in Linux 7". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report