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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章