wget下载
[root@node2 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@node2 src]# ls
mysql-community-client-5.7.40-1.el7.x86_64.rpm mysql-community-libs-5.7.40-1.el7.x86_64.rpm
mysql-community-common-5.7.40-1.el7.x86_64.rpm mysql-community-server-5.7.40-1.el7.x86_64.rpm
mysql-community-devel-5.7.40-1.el7.x86_64.rpm
[root@node2 src]#
安装
[root@node2 src]# yum -y localinstall *.rpm
[root@node2 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@node2 src]#
关闭防火墙和selinux,vi进入/etc/selinux/config将SELINUX=enforcing修改成SELINUX=disabled
[root@node2 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@node2 src]# vi /etc/selinux/config
[root@node2 src]#
设置临时生效开机自启
[root@node2 src]# setenforce 0
[root@node2 src]# systemctl start mysqld
[root@node2 src]# systemctl enable mysqld
[root@node2 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 23:49:53 CST; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 2439 (mysqld)
Tasks: 27 (limit: 11217)
Memory: 285.2M
CGroup: /system.slice/mysqld.service
└─2439 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Dec 27 23:49:49 node2 systemd[1]: Starting MySQL Server...
Dec 27 23:49:53 node2 systemd[1]: Started MySQL Server.
[root@node2 src]#
查询mysql服务端口号
[root@node2 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@node2 src]#
登陆需要密码,但是没有设置密码,需要查看临时密码使用(单次使用,使用完失效)
[root@node2 src]# grep password /var/log/mysqld.log
2022-12-27T15:49:51.160741Z 1 [Note] A temporary password is generated for root@localhost: (NsErcsk!5qF
[root@node2 src]#
连接mysql 密码用单引号包围
[root@node2 src]# mysql -uroot -p'(NsErcsk!5qF'
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.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用户密码
mysql> set password = password("ClsAl20011221!");
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql>
重新登录测试
[root@node2 src]# mysql -uroot -p'ClsAl20011221!'
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 4
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@node2 src]# 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
... 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
... skipping.
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@node2 src]#
授权
mysql> grant all on *.* to 'root'@'192.168.157.131' identified by 'ClsAl20011221!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
安装navicat,连接数据库