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 8.0 for Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Learn how Linux installs mysql 8.0? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

After some effort to download the mysql file, we can begin the installation of Mysql8.0.

Extract the file

/ / decompress the file to generate two compressed files in xz format $tar-xvf mysql-8.0.13-linux-glibc2.12-x86_64.tarmysql-router-8.0.13-linux-glibc2.12-x86_64.tar.xzmysql-test-8.0.13-linux-glibc2.12-x86_64.tar.xz//. We need to delete / remove the original file before we can continue the extraction. Because the extracted .tar file and .tar.xz file are renamed mv mysql-8.0.13-linux-glibc2.12-x86_64.tar.. / xz-d mysql-router-8.0.13-linux-glibc2.12-x86_64.tar.xztar-xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar// to facilitate search, change the name mv mysql-8.0.13-linux-glibc2.12-x86_64.tar mysql8

Environment configuration

We need special mysql process startup users and rights management:

/ / create mysql system users and user groups useradd-r mysql// give mysql permissions to the installation directory chown mysql:mysql-R mysql8

Configure your own mysql configuration file, because I have multiple Mysql libraries, and I manually specify many parameters:

[client] socket=/home/work/lnmp/mysql8/tmp/mysql.sockdefault-character-set= UTF8 [MySQL] basedir=/home/work/lnmp/mysql8/datadir=/home/work/lnmp/mysql8/data/socket=/home/work/lnmp/mysql8/tmp/mysql.sockport=3306user=mysql# specify log time for system time log_timestamps=SYSTEMlog-error=/home/work/lnmp/mysql8/log/mysql.err# specify character set as utf8, because the default character set in mysql8.0 is utfmb4 It will cause compatibility problems with other programs. Default-character-set= UTF8 [mysqld] basedir=/home/work/lnmp/mysql8/datadir=/home/work/lnmp/mysql8/data/socket=/home/work/lnmp/mysql8/tmp/mysql.sockport=3306user=mysqllog_timestamps=SYSTEMcollation-server = utf8_unicode_cicharacter-set-server = utf8# specifies the default authenticated encryption method. The default method in mysql8.0 is caching_sha2_password. Causes compatibility problems with default_authentication_plugin= mysql_native_ password [mysqld _ safe] log-error=/home/work/lnmp/mysql8/log/mysqld_safe.errpid-file=/home/work/lnmp/mysql8/tmp/mysqld.pidsocket=/home/work/lnmp/mysql8/tmp/ mysql.sock [mysql.server] basedir=/home/work/lnmp/mysql8socket=/home/work/lnmp/mysql8/tmp/ mysql.sock [mysqladmin] Socket=/home/work/lnmp/mysql8/tmp/mysql.sock

In this I specify the path of the error log, in the next operation, if there is an error, in addition to check the error displayed by the terminal, but also remember to check the detailed information in the error log.

Because I specified some files, I need to create them in advance:

Mkdir logtouch log/mysql.errtouch log/mysqld_safe.errmkdir tmpchown mysql:mysql-R.. / *

Database initialization

If we do not initialize, directly using bin/mysqld_safe to start will cause an error, because we need to initialize the mysql environment. Refer to the article at this time:

Bin/mysqld-- initialize-- user=mysql-- basedir=/home/work/lnmp/mysql8/-- datadir=/home/work/lnmp/mysql8/data/2018-12-13T06:15:03.159123Z 0 [System] [MY-013169] [Server] / home/work/lnmp/mysql8/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 11902018-12-13T06:15:05.255817Z 5 [Note] [MY-010454] [Server] A temporary password is generated For root@localhost:! / 7oymuru% (XfZ2018-12-13T06:15:06.135143Z 0 [System] [MY-013170] [Server] / home/work/lnmp/mysql8/bin/mysqld (mysqld 8.0.13) initializing of server has completed

The prompt indicates that we have created a user for root and a temporary password, and the initialization is successful.

Start the database

According to the official documentation, we use the mysqld_safe command to launch:

$bin/mysqld_safe2018-12-13T06:16:58.604154Z mysqld_safe Logging to'/ home/work/lnmp/mysql8/log/mysql.err'.2018-12-13T06:16:58.629249Z mysqld_safe Starting mysqld daemon with databases from / home/work/lnmp/mysql8/data

Open the database

The database process has been started, and we can use the mysql database normally on the new terminal:

$ps aux | grep mysql root 2141 0.0 815844 5328 pts/0 S + 14:16 0:00 / bin/sh bin/mysqld_safemysql 2319 1.0 1997492 374448 pts/0 Sl+ 14:16 0:00 / home/work/lnmp/mysql8/bin/mysqld-- basedir=/home/work/lnmp/mysql8/-- datadir=/home/work/lnmp/mysql8/data-- plugin-dir=/home/work/lnmp/mysql8//lib/plugin-- User=mysql-- log-error=/home/work/lnmp/mysql8/log/mysql.err-- pid-file=/home/work/lnmp/mysql8/tmp/mysqld.pid-- socket=/home/work/lnmp/mysql8/tmp/mysql.sock-- port=3306work 25258 0.0 105356 824 pts/1 S + 14:18 0:00 grep mysql

But directly use the mysql command to report an error:

$bin/mysql-urootERROR 2002 (HY000): Can't connect to local MySQL server through socket'/ tmp/mysql.sock' (2)

According to the description of the role of mysql.sock, we can specify the mysql.sock path:

Bin/mysql-S / home/work/lnmp/mysql8/tmp/mysql.sock-h localhost-uroot-pEnter password:

Change the initial password

Using any command after we open the database will prompt us to change the initial temporary password:

Mysql > show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

Change the password:

Mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY' 123456 question question OK, 0 rows affected (0.05sec)

Reconnect and the new password takes effect.

Link global command

At this point, we can only use path / home/work/lnmp/mysql8/bin/mysql or relative path to call mysql, and the link needs to be a global command:

$ln-s / home/work/lnmp/mysql8/bin/mysql / usr/bin/$ ln-s / home/work/lnmp/mysql8/bin/mysql_safe / usr/bin/

Specify the socket file

In version 8.0, I tried a lot of ways to change the default socket path of the mysql command query in my.cnf, but it was still unsuccessful, so I had to link the socket file in the default path:

Ln-s / home/work/lnmp/mysql8/tmp/mysql.sock / tmp/

Then we call the mysql command and there will be no error.

Restart the database

In the process, we may need to restart the database to debug the parameters:

/ / Kill the process, which is equivalent to stopping cat tmp/mysqld.pid | xargs kill// starts mysqlbin/mysqld_safe-- defaults-file=/home/work/lnmp/mysql8/my.cnf normally

Add new users & grant permissions

In mysql8, I create a user and assign a value, and the result is an error:

Mysql > grant all privileges on *. * to root@localhost indentified by '123456 error error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near' indentified by '123456' at line 1

According to online materials, it is because Mysql8 separates the creation of accounts from the granting of permissions:

/ / create account create user 'username' @ 'access host' identified by 'password'; / / grant permission (add with grant option after permission modification) grant permission list on database to 'username' @ 'access host'; / / Refresh permission flush privileges; Thank you for your reading! After reading the above, do you have a general idea of how Linux installs mysql 8.0? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are 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

Servers

Wechat

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

12
Report