0. Of course, there are a variety of MySQL installation methods. on Ubuntu, you can use apt-get to install MySQL. The advantage is that it is fast and convenient. Basically, it will help you solve the dependency problem of all function libraries. Normally, MySQL can be used as long as apt-get is executed completely. However, I prefer to use the source code to install MySQL for many reasons.
0. Description
Of course, MySQL is installed in a variety of ways. on Ubuntu, you can install it using apt-get. The advantage is that it is fast and convenient. Basically, it will help you solve the dependency problem of all function libraries. Normally, MySQL can be used as long as apt-get is executed completely.
However, I prefer to use the source code to install MySQL for a simple reason: in addition to the detailed official documentation, you can also know exactly what you are doing, this will be of great help when MySQL runs in the future!
But even if you install it according to the official documents, you may encounter various problems. Here, I will present a complete process for you to complete the following four tasks:
Download MySQL 5.6
Installation preparation: Install the MySQL dependency function library
Install and run MySQL
Optimize MySQL
(1) Account Security Optimization
(2) database security Optimization
I installed MySQL 15.10 after Ubuntu 5.6, so it is of great reference value!
1. Download MySQL 5.6
: Http://dev.mysql.com/downloads/mysql/5.6.html
After entering, select:
Linux-Generic (glibc 2.5) (x86, 64-bit), Compressed TAR Archive
Or
Linux-Generic (glibc 2.5) (x86, 32-bit), Compressed TAR Archive
It depends on whether you are using 32-bit or 64-bit. Here, I downloaded 64-bit. The downloaded package is as follows:
Linuxidc @ leaf :~ $ Ls mysql *
Mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
--------------------------------------------------------------------------------
2. Installation preparation: Install the MySQL dependency function library
MySQL depends on a function library named libaio and needs to be installed first. Otherwise, problems may occur when installing MySQL later.
As follows:
Linuxidc @ leaf :~ $ Sudo apt-cache search libaio # search for libaio Information
Linuxidc @ leaf :~ $ Sudo apt-get install libaio1 # install libaio1
In this way, you can quickly install the libaio function library.
3. Install and run MySQL
(1) create a user named mysql and a user group respectively.
As follows:
Linuxidc @ leaf :~ $ Sudo groupadd mysql
Linuxidc @ leaf :~ $ Sudo useradd-r-g mysql-s/bin/false mysql
The-r and-s parameters allow the mysql user to have no permission to log on to your system, which ensures system security.
(2) unpack and establish soft links
As follows:
[Root @ leaf ~] # Cd/usr/local
Linuxidc @ leaf:/usr/local $ sudo tar zxvf/home/linuxidc/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
Linuxidc @ leaf:/usr/local $ sudo ln-s/usr/local/mysql-5.6.28-linux-glibc2.5-x86_64/mysql
You need to know that, under normal circumstances, we are used to placing the compiled and installed software in the/usr/local directory. Of course you can choose your own, but we recommend that you put it here.
The advantage of creating a soft link is that if you need to use the mysql installation directory, you do not need to enter a long string of directory names, because the directory of the decompressed mysql package has a long name.
(3) initialize the Data directory
After you unpack MySQL, the MySQL directory contains a data directory:
Linuxidc @ leaf:/usr/local $ cd mysql
Linuxidc @ leaf:/usr/local/mysql $ ls-d data/
Data/
It contains the system information necessary for MySQL to run. Therefore, we need to initialize the data as follows:
# Modify the owner of all files in the mysql directory to mysql
Linuxidc @ leaf:/usr/local/mysql $ sudo chown-R mysql.
# Modify the group of all files in the mysql directory to mysql
Linuxidc @ leaf:/usr/local/mysql $ sudo chgrp-R mysql.
# Initializing data as a mysql user
Linuxidc @ leaf:/usr/local/mysql $ sudo scripts/mysql_install_db -- user = mysql
# Modify the owner of all files in the mysql directory as root.
Linuxidc @ leaf:/usr/local/mysql $ sudo chown-R root.
# Modify the owner of the data directory under the mysql directory to mysql
Linuxidc @ leaf:/usr/local/mysql $ sudo chown-R mysql data
Please be sure to follow the above operations, as to what is the detailed meaning, why do so, can refer to the official documentation, there is a very detailed explanation: http://dev.mysql.com/doc/refman/5.6/en/data-directory-initialization.html
(4) Start MySQL
As follows:
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqld_safe -- user = mysql &
[1] 8365
Linuxidc @ leaf:/usr/local/mysql $160308 14:13:26 mysqld_safe Logging to '/usr/local/mysql-5.6.28-linux-glibc2.5-x86_64/data/leaf. err '.
160308 14:13:26 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.6.28-linux-glibc2.5-x86_64/data
Make sure that the MySQL service is enabled:
Linuxidc @ leaf :~ $ Sudo netstat-antup | grep mysqld
Tcp6 0 0: 3306: * LISTEN 8455/mysqld
The mysql service has been started successfully!
(5) Test the mysql Service
To make mysql better run on your system, we recommend that you perform some mysql service tests as follows:
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqladmin version
Bin/mysqladmin Ver 8.42 Distrib 5.6.28, for linux-glibc2.5 on x86_64
Copyright (c) 2000,201 5, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Server version 5.6.28
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket/tmp/mysql. sock
Uptime: 8 min 36 sec
Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.003
Successful! Then let's warm up the following operations:
# Use mysqladmin to disable the mysql Service
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqladmin-u root shutdown
# Start the mysql Service
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqld_safe -- user = mysql &
# View the default databases in the mysql database
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqlshow
+ -------------------- +
| Databases |
+ -------------------- +
| Information_schema |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
# View the data table in the mysql database (note that this mysql database is an entity, which is different from the above)
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysqlshow mysql
Database: mysql
+ --------------------------- +
| Tables |
+ --------------------------- +
| Columns_priv |
| Db |
| Event |
| Func |
| General_log |
| Help_category |
| Help_keyword |
| Help_relation |
| Help_topic |
| Innodb_index_stats |
| Innodb_table_stats |
| Ndb_binlog_index |
| Plugin |
| Proc |
| Procs_priv |
| Proxies_priv |
| Servers |
| Slave_master_info |
| Slave_relay_log_info |
| Slave_worker_info |
| Slow_log |
| Tables_priv |
| Time_zone |
| Time_zone_leap_second |
| Time_zone_name |
| Time_zone_transition |
| Time_zone_transition_type |
| User |
+ --------------------------- +
# View all user tables in the mysql database
Linuxidc @ leaf:/usr/local/mysql $ sudo bin/mysql-e "SELECT User, Host, plugin FROM mysql. user" mysql
+ ------ + ----------- + ----------------------- +
| User | Host | plugin |
+ ------ + ----------- + ----------------------- +
| Root | localhost | mysql_native_password |
| Root | leaf | mysql_native_password |
| Root | 127.0.0.1 | mysql_native_password |
| Root |: 1 | mysql_native_password |
| Localhost | mysql_native_password |
| Leaf | mysql_native_password |
+ ------ + ----------- + ----------------------- +
Note that the above tests must be performed only when you have started the mysql service. At the same time, if you want to know the detailed explanation of each step, you can refer to the official documentation: http://dev.mysql.com/doc/refman/5.6/en/testing-server.html
To be precise, MySQL has been successfully installed! Next we will do some basic optimization, mainly from the security perspective.
For more details, refer to the highlights on the next page.: Http://www.linuxidc.com/Linux/2016-03/129043p2.htm