目录
下载安装数据库
用wget下载
[root@node1 ~]# cd /usr/src
[root@node1 src]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.40-1.el7.x86_64.rpm http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.40-1.el7.x86_64.rpm http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.40-1.el7.x86_64.rpm http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.40-1.el7.x86_64.rpm http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.40-1.el7.x86_64.rpm
[root@node1 src]# ls
debug mysql-community-devel-5.7.40-1.el7.x86_64.rpm
kernels mysql-community-libs-5.7.40-1.el7.x86_64.rpm
mysql-community-client-5.7.40-1.el7.x86_64.rpm mysql-community-server-5.7.40-1.el7.x86_64.rpm
mysql-community-common-5.7.40-1.el7.x86_64.rpm
[root@node1 src]#
安装
[root@node1 src]# yum -y localinstall *.rpm
[root@node1 src]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@node1 src]#
关闭防火墙和selinux,vi进入/etc/selinux/config将SELINUX=enforcing修改成SELINUX=disabled
[root@node1 src]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node1 src]# vi /etc/selinux/config
设置临时生效和mysql开机自启
[root@node1 src]# setenforce 0
[root@node1 src]# systemctl start mysqld
[root@node1 src]# systemctl enable mysqld
[root@node1 src]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-12-27 21:46:27 CST; 4min 20s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 2617 (mysqld)
Tasks: 27 (limit: 4722)
Memory: 262.0M
CGroup: /system.slice/mysqld.service
└─2617 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Dec 27 21:46:24 node1.example.com systemd[1]: Starting MySQL Server...
Dec 27 21:46:27 node1.example.com systemd[1]: Started MySQL Server.
[root@node1 src]#
查询mysql服务端口号为3306
[root@node1 src]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
[root@node1 src]#
登陆时需要密码,但没有设置密码,需要查看临时密码使用
[root@node1 src]# grep password /var/log/mysqld.log
2022-12-27T13:46:25.515449Z 1 [Note] A temporary password is generated for root@localhost: C;tdKZXDE5aJ
[root@node1 src]#
连接mysql 密码用单引号包围
[root@node1 src]# mysql -uroot -p'C;tdKZXDE5aJ'
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 6
Server version: 5.7.40
Copyright (c) 2000, 2022, 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>
设置mysql的root用户密码 这个root指mysql的root
mysql> set password = password("WangShuai555!");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
重新登录测试
[root@node1 ~]# mysql -uroot -p'WangShuai555!'
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.40 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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>
服务初始化
[root@node1 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n //是否修改密码
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //是否删除匿名用户
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n //是否拒绝root远程连接
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //删除测试数据库和访问它们的权限
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y //重新加载权限表
Success.
All done!
[root@node1 ~]#
授权
mysql> grant all on *.* to 'root'@'192.168.47.1' identified by 'WangShuai555!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
安装navicat,连接数据库
成功