MySQL-Linux install

1:得到mysql服務相關的安裝程序(假裝沒有安裝過,甚至沒有自帶的)

[root@mysql dev]# ll
total 578976
drwxr-xr-x. 2 root root      4096 Apr  5 06:23 mysql
-rw-r--r--. 1 root root 592865280 Sep 27  2019 mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
[root@mysql dev]# 

2:解壓第一步

[root@mysql dev]# tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar 
mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm
mysql-community-test-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
mysql-community-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm
[root@mysql dev]# ll

挪到自定義目錄下

[root@mysql dev]# mkdir mysql
[root@mysql dev]# mv mysql*.rpm ./mysql
[root@mysql dev]# ll
total 578976
drwxr-xr-x. 2 root root      4096 Apr  5 06:23 mysql
-rw-r--r--. 1 root root 592865280 Sep 27  2019 mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
[root@mysql dev]# cd mysql/
[root@mysql mysql]# ll
total 578984
-rw-r--r--. 1 7155 31415  25085192 Jun 24  2017 mysql-community-client-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    278292 Jun 24  2017 mysql-community-common-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   3778852 Jun 24  2017 mysql-community-devel-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  46236988 Jun 24  2017 mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  24077820 Jun 24  2017 mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 128296360 Jun 24  2017 mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2238032 Jun 24  2017 mysql-community-libs-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2115696 Jun 24  2017 mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  55456196 Jun 24  2017 mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 171537176 Jun 24  2017 mysql-community-server-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  15258732 Jun 24  2017 mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 118490200 Jun 24  2017 mysql-community-test-5.7.19-1.el7.x86_64.rpm

mysql-community-server-5.7.19-1.el7.x86_64.rpm、mysql-community-client-5.7.19-1.el7.x86_64.rpm兩個也應該是一定會用到的

3:創建mysql用戶組
先驗證沒有這個用戶組

[root@mysql dev]# groups mysql
groups: mysql: no such user
[root@mysql dev]#

添加用戶組mysql,並未此用戶組添加用戶mysql

[root@mysql dev]# groupadd mysql
[root@mysql dev]# useradd -r -g mysql mysql
[root@mysql dev]# 

賦予權限

[root@mysql dev]# cd mysql/
[root@mysql mysql]# chown -R mysql:mysql ./
[root@mysql mysql]#

4:安裝MySQL Server

[root@mysql mysql]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm  --nodeps --force
[root@mysql mysql]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm  --nodeps --force
warning: mysql-community-server-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.19-1.e################################# [100%]
[root@mysql mysql]# id mysql
uid=991(mysql) gid=1001(mysql) groups=1001(mysql)
[root@mysql mysql]# 

啓動Server

[root@mysql mysql]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit not found.
[root@mysql mysql]# systemctl start mysqld.service
[root@mysql mysql]# 

查看啓動是否成功

[root@mysql mysql]# netstat -anp|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      14979/mysqld        
[root@mysql mysql]#

或者

[root@mysql mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-04-05 07:11:11 CST; 8s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 15510 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 15489 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 15514 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─15514 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Apr 05 07:11:10 mysql systemd[1]: Starting MySQL Server...
Apr 05 07:11:11 mysql systemd[1]: Started MySQL Server.

關閉服務(留作備用):

[root@mysql mysql]# systemctl stop mysqld.service

重啓服務(留作備用):

[root@mysql mysql]# systemctl restart mysqld.service

5:安裝客戶端軟件

[root@mysql mysql]# rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm --nodeps --force
warning: mysql-community-client-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.19-1.e################################# [100%]
[root@mysql mysql]#

登錄

[root@mysql dev]# mysql
ERROR 1045 (28000): Unknown error 1045
[root@mysql dev]#

方式一(不安全):直接不用驗證

[root@mysql dev]# vim  /etc/my.cnf
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables #忽略mysql權限問題,直接登錄

重啓

[root@mysql dev]# systemctl restart mysqld.service
[root@mysql dev]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

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> 

方式二(安全):

[root@mysql dev]# grep  'temporary password' /var/log/mysqld.log
2020-04-04T22:53:33.676655Z 1 [Note] A temporary password is generated for root@localhost: qcwrb-(Wa5Rl
[root@mysql dev]# mysql -uroot  -pqcwrb-(Wa5Rl
bash: syntax error near unexpected token `('
[root@mysql dev]# mysql -uroot  -pqcwrb-\(Wa5Rl
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.19

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

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> 

特殊字符需要做一次轉義。
然而進來以後第一件事情,還是修改密碼:並且需要符合規則“有大小寫字母、有數字、有特殊字符”
在這裏插入圖片描述

每次輸入密碼好麻煩:

[root@mysql ~]# vim /root/.bashrc

在這裏插入圖片描述

[root@mysql ~]# source /root/.bashrc
[root@mysql ~]# mysqlroot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

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> quit
Bye

6:允許遠程訪問:

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> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)

mysql> quit;

放開端口:

[root@mysql ~]# firewall-cmd --permanent --zone=public --add-service=mysql
[root@mysql ~]# firewall-cmd --reload
success
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章