注释:
linux安装mysql服务分两种安装方法:

①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错;

②使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,300M左右。以下介绍linux使用官方编译好的二进制包安装mysql。

下面采用第二种方式安装.
到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic

下载连接:http://dev.mysql.com/downloads/mysql/5.6.html#downloads 官网
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

tar xzvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz 
cp mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/mysql5.6.28 -r
groupadd mysql
useradd -r -g mysql mysql
cd /usr/local/mysql5.6.28/
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql
chown -R root:root ./
chown -R mysql:mysql data
cp support-files/mysql.server /etc/init.d/mysqld 
ln -s /usr/local/mysql5.6.28/bin/mysql /usr/bin/
service mysqld restart
cp mysql-5.6.28-linux-glibc2.5-x86_64/support-files/my-default.cnf /usr/local/mysql5.6.28/my.cnf
ln -s /usr/local/mysql5.6.28/my.cnf /etc/my.cnf

配置Mysql

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
user = mysql
port = 3306
basedir =/usr/local/mysql5.6.28
datadir =/usr/local/mysql5.6.28/data
socket =/tmp/mysql.sock
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci

mysql -u root

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('test');

添加远程超级管理员:
CREATE USER 'BraveDu'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON . TO 'BraveDu'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;

想使用远程登录确保: mysql 端口是否加入防火墙,如果没有的话 请执行下面这句 :

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

当然mysql 默认使用的端口是 3306 为了安全起见建议修改.
通过修改 /etc/my.cnf 修改 port

相关帐号创建:

        #创建数据库  DB_NAME 更换为你的数据库名
        CREATE DATABASE `DB_NAME`CHARACTER SET utf8 COLLATE utf8_general_ci;
        
        #创建所属用户 USERNAME 为用户名
        CREATE USER 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD';
        FLUSH PRIVILEGES;
        
        #为此用户对应的数据库授权  DB_NAME 为数据库  USERNAME 为对应用户名
        GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW,
 DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SELECT, SHOW VIEW, TRIGGER, 
    UPDATE ON `DB_NAME`.* TO 'USERNAME'@'%' WITH GRANT OPTION;
        
        #创建 localhost 用户
        CREATE USER 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD'; 
        FLUSH PRIVILEGES;
        
        #对localhost用户授权
        GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, 
DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SELECT, SHOW VIEW, TRIGGER, 
    UPDATE ON `DB_NAME`.* TO 'USERNAME'@'localhost' WITH GRANT OPTION;