Install and start MySQL in Linux

Source: Internet
Author: User

Install and start MySQL in Linux
I. Comparison of various MySQL installation methods

In Linux, MySQL has three major installation methods: RPM installation, binary installation, and source code installation. The advantages and disadvantages of the three installation methods are shown in the following table:

  RPM Installation Binary Installation Source code Installation
Advantages Easy to install and suitable for beginners Easy to install and can be installed in any path You can customize the compilation as needed, which is flexible and has the best performance.
Disadvantages You need to download the server and client separately. The installation path is not flexible enough and cannot be modified by default. It has been compiled, and the performance is not as good as that of the source code installation. You cannot flexibly customize the compilation parameters. Complicated installation process and long Compilation Time
File Layout
  • /Usr/bin (client programs and scripts)
  • /Usr/sbin (mysqld server)
  • /Var/lib/mysql (log files and databases)
  • /Usr/include/mysql (header file)
  • /Usr/lib/mysql (library file)
  • /Usr/share/mysql (error message and character set file)
  • Bin (mysqld server and client program)
  • Data (log files and databases)
  • Include (header file)
  • Lib (library file)
  • Scripts (mysql_install_db script)
  • Share/mysql (error message)
 
Ii. Instructions on RPM Installation

Access ingress:

Run the following command to complete the installation.

1 rpm -ivh MySQL-devel-5.6.31-1.el6.x86_64.rpm
Iii. Binary installation process description

(1) Add mysql users and user groups

12 groupadd mysqluseradd -g mysql mysql

(2) decompress the binary installation package and place it in the specified directory.

(3) initialize the database and create the basic table of the database.

1 ./mysql_install_db --user=mysql

(4) set the directory permissions as needed.

Iv. Source Code Installation Process

(1) download and decompress the source code package.

(2) install necessary software packages.

1234 1.cmake2.ncurses-devel yum install cmake ncurses-devel -y

(3) create users and groups

12 groupadd mysqluseradd mysql -s /sbin/nologin -M -g mysql

(4) Compile parameters and install

12345678910111213141516171819 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.28 \-DMYSQL_DATADIR=/usr/local/mysql-5.6.28/data \-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.28/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=uft8_general_ci \-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \-DENABLED_LOCAL_INFILE=ON \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \-DWITH_FAST_MUTEXES=1 \-DWITH_ZLIB=bundled \-DENABLED_LOCAL_INFILE=1 \-DWITH_READLINE=1 \-DWITH_EMBEDDED_SERVER=1 \-DWITH_DEBUG=0 make && make install

(5) generate a link directory

1 ln -s /usr/local/mysql-5.6.28 /usr/local/mysql

(6) add Environment Variables

12 echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profilesource /etc/profile

(7) modify directory permissions

1 chown -R mysql.mysql /usr/local/mysql-5.6.28

(8) initialize the database and generate the basic table

12 /usr/local/mysql/scripts./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

(9) configure the MySQL Startup File

123 cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqld

V. MySQL startup and Shutdown

(1) For RPM installation, you can use system services to start and close MySQL.

12 Service mysqld start # start mysqlService mysqld stop # disable mysql

(2) For binary and source code installation, you can find the mysql Startup file from the installation directory (refer to step 1 of the compilation and installation process. Of course, you can also compile one by yourself ), then copy to/etc/init. d/mysqld to start and close MySQL. You can also use the chkconfig command to add it to the system service.

123 /Etc/init. d/mysqld start # start mysql/Etc/init. d/mysqld stop # disable mysql/Etc/init. d/mysqld restart # restart mysql

(3) Basic principles of MySQL startup

/Etc/init. d/mysqld is a shell script. During the startup process, mysqld_safe script is called and the mysqld service is called to start mysql. As shown below, the mysqld_safe program is called in the/etc/init. d/mysqld script.

1 $bindir/mysql_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &

(4) In addition, we can use the mysqladmin command to close MySQL.

1 Mysqladmin-uroot-ppassword shutdown # Only the root user with mysql can perform the shutdown operation.

(5) MySQL shutdown method not recommended in non-test environments

123 killall mysqldpkill mysqldkillall -9 mysqld

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.