Home > Database > Mysql Tutorial > linux source code installation mysql

linux source code installation mysql

WBOY
Release: 2023-05-23 11:20:07
Original
514 people have browsed it

In the Linux operating system, it is necessary to install and configure the MySQL database server because it is a high-performance, reliable and widely used database management system. MySQL runs on different operating systems and allows you to customize and optimize it using open source code.

Since most Linux distributions include MySQL packages in their software repositories, some users may wish to install the software from source so that they can choose its features and configuration. In this article, you will be shown how to install MySQL from source code on a Linux server.

  1. Preparing the MySQL source code on the Linux server

First, download the latest version of the MySQL source code from the MySQL official website. Extract the downloaded source code files from the download folder into the directory where you wish to install MySQL. If you are installing MySQL in the /var/lib/mysql folder on Linux, you can extract the source code to that folder using the following command:

tar -xzvf mysql-5.7.33.tar.gz -C /var/lib/mysql
Copy after login
  1. Install Basic Build Tools and Libraries

Before proceeding with the MySQL source code installation, you need to install the basic tools and libraries for compiling and building MySQL by running the following commands:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libtool autoconf
sudo apt-get install libssl-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libncurses5-dev
Copy after login

Please note that these commands will install all Required build tools and libraries, specifically the OpenSSL library, zlib, and ncurses, so that MySQL can monitor and read user input in the application.

  1. Configure MySQL build

After completing the installation of basic build tools and libraries, you need to configure the subsequent MySQL compilation and build process.

First, create the required folders in the MySQL installation directory using the following command:

sudo mkdir /var/lib/mysql/data
sudo mkdir /var/lib/mysql/logs
sudo mkdir /var/lib/mysql/tmp
Copy after login

Then, build MySQL using the following command:

sudo ./configure --with-charset=utf8mb4 --with-collation=utf8mb4_general_ci --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=innodb,archive,csv,blackhole --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --without-docs --without-man --without-test --without-bench
Copy after login

While running this command , if you encounter any dependency errors, follow the instructions provided in the error message to install the missing libraries.

Building MySQL may take a while, depending on your server's processing power.

  1. Compile and install MySQL

After you have built MySQL using the build command, you can use the following command to compile and install MySQL into a directory of your choice:

sudo make
sudo make install
Copy after login

With the above command, you can install MySQL in the /usr/local/mysql directory.

  1. Configuring MySQL database

After the construction and installation of MySQL is completed, you can configure it according to the following process:

First, configure it in /etc/my Basic configuration of MySQL in the .cnf file:

sudo nano /etc/my.cnf
Copy after login

Then, add the following content in the file:

[mysqld]
datadir=/var/lib/mysql/data
user=mysql
log_error=/var/lib/mysql/logs/error.log
log-bin=/var/lib/mysql/tmp/log/binary
innodb_log_file_size=1G
innodb_buffer_pool_size=4G
innodb_buffer_pool_instances=2
innodb_flush_log_at_trx_commit=0
max_connections=20000
default_authentication_plugin=mysql_native_password
skip_name_resolve
Copy after login

By adding these parameters in the /my.cnf file, you can configure the MySQL server for Configure default data directories, users, and logging options.

  1. Start the MySQL server

After installing and configuring MySQL, start the MySQL server in the terminal:

sudo /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
Copy after login

Now you can check using the following command Is MySQL installed correctly:

sudo /usr/local/mysql/bin/mysql
Copy after login

After you see the MySQL database prompt, you can use it to create and manage the database.

  1. Add username and password to MySQL

After starting MySQL in the previous step, you need to add username and password to MySQL. These credentials will be used for the security of the MySQL database. access.

First, log in to the MySQL console as the root user using the following command:

mysql -u root
Copy after login

After entering MySQL, use the following command to add a new user and password:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Copy after login

This command A new MySQL user myuser will be created with the password mypassword.

  1. Test MySQL database

After the MySQL database is installed and configured, you need to use the following test command to verify that the database is available and running normally:

mysqladmin -u myuser -p version
Copy after login

After prompting for a password, enter the configured MySQL database password. If everything is fine, you will see output about the MySQL version and other relevant information, which means you have successfully installed and configured the MySQL database.

The above is the detailed content of linux source code installation mysql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template