Linux in practice: Deploying various software
MySQL5.7 version installed on CentOS system
Installation (requires root privileges or sudo privilege escalation)
-
Configure the yum warehouse
# 更新密钥 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 安装Mysql yum库 rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
Since MySQL is not in the official repository of CentOS, we use the above rpm command:
- Import the key for the MySQL repository
- Configure the yum warehouse of MySQLQ
-
Install MySQL using yum
# yum安装Mysql yum -y install mysql-community-server
-
After the installation is complete, start MySQL and configure it to start automatically at boot
systemctl start mysqld # 启动 systemctl enable mysqld # 开机自启
After the MySQL installation is complete, it will be automatically configured as
mysqld
a service named: , which can be managed by systemctl -
Check the running status of MySQL
systemctl status mysqld
configuration
Mainly configure the password of the administrator user root and configure the permission to allow remote login.
-
Obtain the initial password of MySQL
# 通过grep命令,在/var/log/mysqld.log文件中,过滤temporary password关键字,得到初始密码 cat /var/log/mysqld.log | grep "temporary password"
[In the returned results, ... root@localhost: xxxxxx, this xxxxxx is the root password]
-
Log in to the MySQL database system
# 执行 mysql -uroot -p # 解释 # -u,登陆的用户,MySQL数据库的管理员用户同Linux一样,是root # -p,表示使用密码登陆 # 执行完毕后输入刚刚得到的初始密码,即可进入MySQL数据库
-
Change root user password
# 在MySQL控制台内执行 ALTER USER 'root'@'localhost' IDENTIFIED BY '密码'; -- 密码需要符合:大于8位,有大写字母,有特殊符号
-
[Extended], configure a simple password for root
We can set a simple password for root, such as 123456.
Please note that this configuration is only for MySQL in the test environment or learning environment. If it is for official use, please do not set a simple password
# 如果你想设置简单密码,需要降低Mysql的密码安全级别 set global validate_password_policy=LOW; # 密码安全级别低 set global validate_password_length=4; # 密码长度最低4位即可 # 然后就可以用简单密码了(这里使用简单密码,为了方便,生产中不要这样) ALTER USER 'root'@'localhost' IDENTIFIED BY '简单密码';
-
[Extended], configure root to run remote login
By default, the root user does not enable remote login, and is only allowed to log in to the MySQL system on the Linux server where MySQL is located.
Be aware that allowing root remote logins is a security risk
# 授权root远程登录 grant all privileges on *.* to root@"IP地址" identified by '密码' with grant option; # IP地址即允许登陆的IP地址,也可以填写%,表示允许任何地址 # 密码表示给远程登录独立设置密码,和本地登陆的密码可以不同 # 刷新权限,生效 flush privileges;
-
Exit the MySQL console page
# 退出命令 exit # 或者通过快捷键退出:ctrl + d
-
check port
MySQL is bound to port 3306 by default, you can check the network status of MySQL through port occupation
netstat -anp | grep 3306
At this point, MySQL is installed and available. Please keep the MySQL root password well.
MySQL8.0 version installed on CentOS system
Install
-
Configure the yum warehouse
# 更新密钥 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 安装Mysql8.x版本 yum库 rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
-
Install MySQL using yum
# yum安装Mysql yum -y install mysql-community-server
-
After the installation is complete, start MySQL and configure it to start automatically at boot
systemctl start mysqld # 启动 systemctl enable mysqld # 开机自启
After the MySQL installation is complete, it will be automatically configured as
mysqld
a service named: , which can be managed by systemctl -
Check the running status of MySQL
systemctl status mysqld
configuration
Mainly modify the root password and allow root remote login
-
Obtain the initial password of MySQL
# 通过grep命令,在/var/log/mysqld.log文件中,过滤temporary password关键字,得到初始密码 grep 'temporary password' /var/log/mysqld.log
-
Log in to the MySQL database system
# 执行 mysql -uroot -p # 解释 # -u,登陆的用户,MySQL数据库的管理员用户同Linux一样,是root # -p,表示使用密码登陆 # 执行完毕后输入刚刚得到的初始密码,即可进入MySQL数据库
-
change root password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; -- 密码需要符合:大于8位,有大写字母,有特殊符号,不能是连续的简单语句如123,abc
-
[Extended], configure a simple password for root
We can set a simple password for root, such as 123456.
Please note that this configuration is only for MySQL in the test environment or learning environment. If it is for official use, please do not set a simple password
set global validate_password.policy=0; # 密码安全级别低 set global validate_password.length=4; # 密码长度最低4位即可
-
Allow root to log in remotely and set a remote login password
By default, the root user does not enable remote login, and is only allowed to log in to the MySQL system on the Linux server where MySQL is located.
Be aware that allowing root remote logins is a security risk
# 第一次设置root远程登录,并配置远程密码使用如下SQL命令 create user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码!'; -- 密码需要符合:大于8位,有大写字母,有特殊符号,不能是连续的简单语句如123,abc # 后续修改密码使用如下SQL命令 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
-
Exit the MySQL console page
# 退出命令 exit # 或者通过快捷键退出:ctrl + d
-
check port
MySQL is bound to port 3306 by default, you can check the network status of MySQL through port occupation
netstat -anp | grep 3306
At this point, MySQL is installed and available. Please keep the MySQL root password well.
MySQL5.7 version is installed in Ubuntu (WSL environment) system
The installation operation requires root privileges, you can:
-
Switch to the root user via su
-
Or add sudo before each command to temporarily elevate privileges
Install
-
Download the apt repository file
# 下载apt仓库的安装包,Ubuntu的安装包是.deb文件 wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
-
Configure the apt repository
# 使用dpkg命令安装仓库 dpkg -i mysql-apt-config_0.8.12-1_all.deb
Select in the pop-up box:
ubuntu bionic
(The code name of the Ubuntu 18.04 system is bionic, select the version library of 18.04 for installation)In the pop-up box select:
MySQL Server & Cluster
In the pop-up box select:
mysql-5.7
Final choice:
ok
-
Update the information of the apt repository
# 首先导入仓库的密钥信息 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 # 更新仓库信息 apt update
-
Check whether the warehouse of MySQL5.7 is successfully configured
apt-cache policy mysql-server
See the words as shown in the picture, that is success
-
Install MySQL5.7
# 使用apt安装mysql客户端和mysql服务端 apt install -f -y mysql-client=5.7* mysql-community-server=5.7*
Enter the root password in the pop-up box and select ok, the password is arbitrary
Enter the root password again to confirm
-
start mysql
/etc/init.d/mysql start # 启动 /etc/init.d/mysql stop # 停止 /etc/init.d/mysql status # 查看状态
-
Initialize MySQL
# 执行如下命令,此命令是MySQL安装后自带的配置程序 mysql_secure_installation # 可以通过which命令查看到这个自带程序所在的位置 root@DESKTOP-Q89USRE:~# which mysql_secure_installation /usr/bin/mysql_secure_installation
-
enter password:
-
Whether to enable the password verification plug-in, if you need to enhance the security of the password, enter
y
and press Enter, no need to press Enter directly (here choose to press Enter directly) -
Whether to change the root password, you need to press
y
Enter, you don’t need to press Enter directly (here you choose to press Enter directly) -
Whether to remove the anonymous user, remove the input and press
y
enter, or directly enter without removing (selected to remove here) -
Whether to enable remote login of the root user, prohibit input and press
y
return, and do not prohibit direct press return (here, direct press return is selected) -
Whether to remove the built-in test database, remove the input and press
y
Enter, or directly press Enter without removing it (here choose to press Enter directly) -
Whether to refresh the permission, refresh the input and press
y
Enter, and press Enter without refreshing (here choose to refresh)
-
-
Login to MySQL
mysql -uroot -p # 输入密码即可登陆成功
So far, the MySQL5.7 version has been successfully installed on Ubuntu.
MySQL8.0 version is installed in Ubuntu (WSL environment) system
The latest version of Ubuntu 22.04, the built-in MySQL of this version of the software store is version 8.0
So it can be installed directly through apt
The installation operation requires root privileges, you can:
-
Switch to the root user via su
-
Or add sudo before each command to temporarily elevate privileges
Install
-
If you have already installed MySQL5.7, you need to uninstall the warehouse information
# 卸载MySQL5.7版本 apt remove -y mysql-client=5.7* mysql-community-server=5.7* # 卸载5.7的仓库信息 dpkg -l | grep mysql | awk '{print $2}' | xargs dpkg -P
-
Update apt warehouse information
apt update
-
install mysql
apt install -y mysql-server
-
start mysql
/etc/init.d/mysql start # 启动 /etc/init.d/mysql stop # 停止 /etc/init.d/mysql status # 查看状态
-
Log in to MySQL and set a password
# 直接执行:mysql mysql
-
set password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
-
exit the mysql console
exit
-
Initialize MySQL
# 执行如下命令,此命令是MySQL安装后自带的配置程序 mysql_secure_installation # 可以通过which命令查看到这个自带程序所在的位置 root@DESKTOP-Q89USRE:~# which mysql_secure_installation /usr/bin/mysql_secure_installation
-
enter password:
-
Whether to enable the password verification plug-in, if you need to enhance the security of the password, enter
y
and press Enter, no need to press Enter directly (here choose to press Enter directly) -
Whether to change the root password, you need to press
y
Enter, you don’t need to press Enter directly (here choose to press Enter directly) -
Whether to remove anonymous users, remove the input and press
y
Enter, or directly press Enter without removing (choose to remove here) -
Whether to enable remote login of the root user, prohibit input and press
y
return, and do not prohibit direct press return (here choose direct press return) -
Whether to remove the built-in test database, remove the input and press
y
Enter, or directly press Enter if you do not remove it (here choose to press Enter directly) -
Whether to refresh the permission, refresh the input and press
y
Enter, and press Enter without refreshing (select refresh here)
-
-
Log in to MySQL again (with the changed password)
mysql -uroot -p
So far, the MySQL5.7 version has been successfully installed on Ubuntu.