Linux安装Mysql5.7以及常见问题

Mysql,架构+大数据进阶

Posted by Steven on 2020-09-18
Estimated Reading Time 9 Minutes
Words 1.6k In Total
Viewed Times

一、下载

image-20211219184556262

二、安装

1、解压

1
[root@VM-229-169-centos home]# tar -zxvf ft_local/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@VM-229-169-centos home]# mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/
[root@VM-229-169-centos home]# cd /usr/local/
[root@VM-229-169-centos local]# ll
total 64
drwxr-xr-x 3 root root 4096 Feb 27 2020 agenttools
drwxr-xr-x 2 root root 4096 Nov 2 2020 bin
drwxr-xr-x 2 root root 4096 Feb 10 2020 etc
drwxr-xr-x 2 root root 4096 Feb 10 2020 games
drwxr-xr-x 2 root root 4096 Feb 10 2020 include
drwxr-xr-x 3 root root 4096 Nov 2 2020 lib
drwxr-xr-x 2 root root 4096 Feb 10 2020 lib64
drwxr-xr-x 2 root root 4096 Feb 10 2020 libexec
drwxr-xr-x 9 root root 4096 Sep 18 00:09 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 4096 Jan 8 2021 qcloud
drwxr-xr-x 3 root root 4096 May 29 2020 sa
drwxr-xr-x 2 root root 4096 Feb 10 2020 sbin
drwxr-xr-x 5 root root 4096 Apr 13 2020 share
drwxr-xr-x 2 root root 4096 Feb 10 2020 src
drwxr-xr-x 2 root root 4096 Jul 14 2020 tencent
drwxr-xr-x 9 root root 4096 Oct 28 2020 TsysAgent
[root@VM-229-169-centos local]# mv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql5.7
[root@VM-229-169-centos local]# ll
total 64
drwxr-xr-x 3 root root 4096 Feb 27 2020 agenttools
drwxr-xr-x 2 root root 4096 Nov 2 2020 bin
drwxr-xr-x 2 root root 4096 Feb 10 2020 etc
drwxr-xr-x 2 root root 4096 Feb 10 2020 games
drwxr-xr-x 2 root root 4096 Feb 10 2020 include
drwxr-xr-x 3 root root 4096 Nov 2 2020 lib
drwxr-xr-x 2 root root 4096 Feb 10 2020 lib64
drwxr-xr-x 2 root root 4096 Feb 10 2020 libexec
drwxr-xr-x 9 root root 4096 Sep 18 00:09 mysql5.7
drwxr-xr-x 9 root root 4096 Jan 8 2021 qcloud
drwxr-xr-x 3 root root 4096 May 29 2020 sa
drwxr-xr-x 2 root root 4096 Feb 10 2020 sbin
drwxr-xr-x 5 root root 4096 Apr 13 2020 share
drwxr-xr-x 2 root root 4096 Feb 10 2020 src
drwxr-xr-x 2 root root 4096 Jul 14 2020 tencent
drwxr-xr-x 9 root root 4096 Oct 28 2020 TsysAgent

2、安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@VM-229-169-centos local]# groupadd mysql
[root@VM-229-169-centos local]# useradd -r -g mysql mysql
[root@VM-229-169-centos local]# mkdir /data/mysql
[root@VM-229-169-centos local]# chown mysql:mysql -R /data/mysql
[root@VM-229-169-centos local]# vim /etc/my.cnf
[root@VM-229-169-centos local]# cd /usr/local/mysql5.7/bin/
[root@VM-229-169-centos bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.7/ --datadir=/data/mysql/ --user=mysql --initialize
[root@VM-229-169-centos bin]# vim /data/mysql/mysql.err
[root@VM-229-169-centos bin]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit mysqld.service not found.
[root@VM-229-169-centos bin]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service not found.
[root@VM-229-169-centos bin]# vi /etc/profile
[root@VM-229-169-centos bin]# source /etc/profile

3、启动

1
2
3
4
5
6
7
8
[root@VM-229-169-centos bin]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service not found.
[root@VM-229-169-centos bin]# /etc/init.d/ | grep mysql
-bash: /etc/init.d/: Is a directory
[root@VM-229-169-centos bin]# cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysql
[root@VM-229-169-centos bin]# service mysql start
Starting MySQL. SUCCESS!

4、依赖安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@VM-229-169-centos bin]# mysql -u root -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@VM-229-169-centos bin]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@VM-229-169-centos bin]# yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-devel antoconf automake
Last metadata expiration check: 0:32:06 ago on Fri 17 Sep 2021 11:46:19 PM CST.
Package make-1:4.2.1-10.tl3.x86_64 is already installed.
Package gcc-8.3.1-5.el8.0.2.x86_64 is already installed.
Package gcc-c++-8.3.1-5.el8.0.2.x86_64 is already installed.
Package bison-3.0.4-10.tl3.x86_64 is already installed.
Package ncurses-6.1-7.20180224.tl3.x86_64 is already installed.
Package ncurses-devel-6.1-7.20180224.tl3.x86_64 is already installed.
No match for argument: antoconf
Package automake-1.16.1-6.tl3.noarch is already installed.
Error: Unable to find a match: antoconf
[root@VM-229-169-centos bin]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@VM-229-169-centos bin]# yum install libncurses*
Last metadata expiration check: 0:32:29 ago on Fri 17 Sep 2021 11:46:19 PM CST.
Package ncurses-c++-libs-6.1-7.20180224.tl3.x86_64 is already installed.
Package ncurses-libs-6.1-7.20180224.tl3.x86_64 is already installed.
Dependencies resolved.
======================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================================================================================================
Installing:
ncurses-compat-libs x86_64 6.1-7.20180224.tl3 TencentOS 327 k

Transaction Summary
======================================================================================================================================================================================================================================================
Install 1 Package

Total download size: 327 k
Installed size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
ncurses-compat-libs-6.1-7.20180224.tl3.x86_64.rpm 1.0 MB/s | 327 kB 00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.0 MB/s | 327 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ncurses-compat-libs-6.1-7.20180224.tl3.x86_64 1/1
Running scriptlet: ncurses-compat-libs-6.1-7.20180224.tl3.x86_64 1/1
Verifying : ncurses-compat-libs-6.1-7.20180224.tl3.x86_64 1/1

Installed:
ncurses-compat-libs-6.1-7.20180224.tl3.x86_64

Complete!

5、使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[root@VM-229-169-centos bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET PASSWORD = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from users;
ERROR 1146 (42S02): Table 'mysql.users' doesn't exist
mysql> select * from user;
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | N | 2021-09-18 00:19:27 | 0 | N |
| localhost | mysql.session | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N | 2021-09-18 00:13:03 | NULL | Y |
| localhost | mysql.sys | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N | 2021-09-18 00:13:03 | NULL | Y |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
3 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

mysql> exit;
Bye

6、重启

1
2
3
[root@VM-229-169-centos bin]# service mysql restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!

三、参考

https://cloud.tencent.com/developer/article/1451186

https://www.cnblogs.com/bbdong/p/9579794.html


如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !