The advantage of MySQL binary installation is that it can be installed in any path and has good flexibility. It can also be installed on one server Multiple MySQL instances. The disadvantage of this method is that it is compiled, so the performance is not as good as the version compiled from source code, and the compilation parameters cannot be flexibly customized. If the user does not want to install the simplest but inflexible RPM package, nor does he want to install a complex and time-consuming source code package, then the compiled binary package will be the best choice.
mysql official website: https://dev.mysql.com/downloads/mysql/
Because I downloaded the mysql-8.0.23-linux-glibc2.12-x86_64.tar version, if there is the latest version, just download the latest version.
Transfer the installation package to the linux system package directory through the Xftp tool:
##3.mysql DeploymentExtract the mysql installation package--切换到安装目录 cd /app --解压xz压缩文件 tar -xvf /app/package/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xzModify the mysql folder name
--把mysql-8.0.23-linux-glibc2.12-x86_64修改为mysql文件夹名称 mv /app/mysql-8.0.23-linux-glibc2.12-x86_64 /app/mysqlCreate the data directory
--在mysql根目录下创建data目录,用于存放数据 mkdir /app/mysql/dataCreate the mysql user group and mysql user
--创建mysql用户组和mysql用户 groupadd mysql useradd -g mysql mysqlModify mysql directory permissions
--修改mysql目录权限 chown -R mysql.mysql /app/mysql/Initialize database
--先切换到mysql安装目录 cd /app/mysql --初始化数据库 bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/mysql/dataConfigure mysql
--先切换到mysql.support-files目录 cd /app/mysql/support-files --在mysql/support-files创建文件my-default.cnf touch my-default.cnf --复制配置文件到/etc/my.cnf cp -a ./my-default.cnf /etc/my.cnf --编辑my.cnf vim /etc/my.cnfmy.cnf Enter the following configuration content:
[client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 user=mysql socket=/tmp/mysql.sock basedir=/app/mysql datadir=/app/mysql/dataConfigure environment variables
--编辑profile文件 vim /etc/profile --配置mysql环境变量 PATH=/data/mysql/bin:/data/mysql/lib:$PATH export PATH --使mysql环境变量生效 source /etc/profile --看环境变量是否生效 echo $PATHStart mysql
cd /app/mysql/bin systemctl start mysqld or service mysql startYou may encounter the following error when starting mysql:
Failed to start mysqld. service: Unit not found.or##Starting MySQL.Logging to '/app/mysql/data/dengwu.err '.
... ERROR! The server quit without updating PID file (/app/mysql/data/dengwu.pid).
The solution is as follows:
--需要安装mariadb-server yum install -y mariadb-server --然后启动mariadb服务 systemctl start mariadb.service --需要的可以添加mariadb服务开机启动 systemctl enable mariadb.serviceJob for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
The solution is as follows:
chown -R mysql.mysql /app/mysql/Starting MySQL... ERROR! The server quit without updating PID file (/app/mysql/data /dengwu.pid).
The solution is as follows:
--查看mysql进程 ps -ef|grep mysqld --杀死mysql进程 kill -9 mysql进程ID
Then restart mysql:
4. Modification mysql password
--编辑my.cnf vim /etc/my.cnf
Enter the following command Line:
default_authentication_plugin=mysql_native_password
If you forget your password, add:
--跳过密码验证(等设置了密码就去掉) skip-grant-tables
Then log in to mysql:
--登录mysql mysql -u root -p
Then enter the command to view the mysql user group:
--查看mysql用户表 select user,host,authentication_string from mysql.user;
Check that the root user has not enabled remote connection permissions. If not, execute the following command:
--修改root用户可以远程连接 update mysql.user set host='%' where user='root';
After enabling remote connection permissions, change the root user password:
--如果host是localhost则@字符后面是localhost,反之则是%,以host结果为准 --修改加密规则 alter user 'root'@'%' identified by 'qwer1234' password expire never; --更新一下用户的密码 alter user 'root'@'%' identified with mysql_native_password by 'qwer1234'; --刷新权限 flush privileges; --修改root用户密码 alter user 'root'@'%' identified by 'qwer1234';
If the firewall is turned on, you need to add permission to allow mysql port access. The specific command is as follows:
--允许访问 firewall-cmd --permanent --zone=public --add-port=3306/tcp --重新加载 firewall-cmd --reload --查看是否开通访问权限 firewall-cmd --permanent --zone=public --query-port=3306/tcp
Then restart mysql:
--重新启动mysql service mysql restart;
5. Configure mysql Alibaba Cloud Security Group Policy
Successful connection using Navicat:
The above is the detailed content of How to install MySQL database in Linux environment. For more information, please follow other related articles on the PHP Chinese website!