How to install MySQL database in Linux environment
1. Overview
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.
2. Preparation
2.1 Download the mysql binary installation package
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.
2.2 Import the mysql binary installation package
Transfer the installation package to the linux system package directory through the Xftp tool:
--切换到安装目录 cd /app --解压xz压缩文件 tar -xvf /app/package/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
--把mysql-8.0.23-linux-glibc2.12-x86_64修改为mysql文件夹名称 mv /app/mysql-8.0.23-linux-glibc2.12-x86_64 /app/mysql
--在mysql根目录下创建data目录,用于存放数据 mkdir /app/mysql/data
--创建mysql用户组和mysql用户 groupadd mysql useradd -g mysql mysql
--修改mysql目录权限 chown -R mysql.mysql /app/mysql/
--先切换到mysql安装目录 cd /app/mysql --初始化数据库 bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data
--先切换到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.cnf
[client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 user=mysql socket=/tmp/mysql.sock basedir=/app/mysql datadir=/app/mysql/data
--编辑profile文件 vim /etc/profile --配置mysql环境变量 PATH=/data/mysql/bin:/data/mysql/lib:$PATH export PATH --使mysql环境变量生效 source /etc/profile --看环境变量是否生效 echo $PATH
cd /app/mysql/bin systemctl start mysqld or service mysql start
Failed to start mysqld. service: Unit not found.
... 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.service
The solution is as follows:
chown -R mysql.mysql /app/mysql/
The solution is as follows:
--查看mysql进程 ps -ef|grep mysqld --杀死mysql进程 kill -9 mysql进程ID
Then restart mysql:
4. Modification mysql password
The root user logs in to mysql for the first time, because we don’t know the initial password. Under normal circumstances, we will reset a new password. The specific operations are as follows:
--编辑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
Log in to Alibaba Cloud->Security Group Rules->Access Rules->Inbound Direction->Manually add the following 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

Gate.io is a highly acclaimed cryptocurrency trading platform known for its extensive token selection, low transaction fees and a user-friendly interface. With its advanced security features and excellent customer service, Gate.io provides traders with a reliable and convenient cryptocurrency trading environment. If you want to join Gate.io, please click the link provided to download the official registration installation package to start your cryptocurrency trading journey.
