Home >Database >Mysql Tutorial >How to install mysql on centos tar
How to install MySQL on CentOS using tar package
MySQL is a widely used relational database management system. It is open source software and can run on various operating systems. There are usually multiple methods to choose from for installing MySQL on CentOS, but installing MySQL using a tarball is a very simple method. This article will show you how to install MySQL on CentOS using a tar package.
Step 1: Prepare the installation environment
Before installing MySQL, you need to prepare some prerequisites to ensure that MySQL can run on the system. Here are the prerequisites you need to prepare:
1. Make sure you have the latest version of CentOS system,
2. Install the necessary dependencies and software: gcc, gcc-c, make, cmake and ncurses-devel.
yum -y install gcc gcc-c make cmake ncurses-devel
Step 2: Download MySQL
Install MySQL by downloading the tar package from the MySQL official website. You can find the latest version of MySQL at https://dev.mysql.com/downloads/mysql/.
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.31.tar.gz
Step 3: Unzip the tar package
Before installing MySQL, we need to unzip the tar package to the specified directory. This can be done using the following command:
tar -zxvf mysql-5.7.31.tar.gz
Step 4: Create MySQL users and groups
In order to use MySQL correctly, We need to create a user and group, generate the MySQL default storage directory and grant permissions to it. Here we will create a user and group named "mysql".
groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /usr/local/mysql/data
touch /var/log/mysql.log
Step 5: Compile and install MySQL
Next, we need to compile MySQL using the following command
cd mysql-5.7.31
cmake \
-DCMAKE_INSTALL_PREFIX= /usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DFORCE_INSOURCE_BUILD=1
See the picture below, indicating that the configuration is successful
Next compile MySQL using the command
make
Then, you need to install MySQL using the following command.
make install
Step 6. Configure MySQL
Now, we need to configure MySQL. The MySQL configuration file is located at /usr/local/mysql/etc/my.cnf. However, we can easily generate a new my.cnf file using the following command.
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Verify whether the SQL installation is correct
service mysql start
mysql -u root -p
When entering the default password, you need to find it in the log file
cat /var/log/mysql.log | grep 'A temporary password' | tail -1 | awk -F '[ ]' '{print $NF}'
It will return a random password. Use this password to log in and change your password.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Okay, now you have successfully installed MySQL using the tar package on CentOS. As you can see, this is a very simple method that you can easily use in any system and application that needs to use MySQL.
The above is the detailed content of How to install mysql on centos tar. For more information, please follow other related articles on the PHP Chinese website!