Centos7安装mysql5.7.13

查看是否安装mysql:

mysql --version

 mysql  Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using  EditLine wrapper

查看是否安装cmake:

输入命令:cmake -help

3.安装cmake包

# wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz

# tar zxvf cmake-3.5.2.tar.gz

# cd cmake-3.5.2/

# ./bootstrap

# gmake

# gmake install 

 

4.创建mysql的安装目录及数据库存放目录

# mkdir -p /usr/local/mysql                 //安装mysql

# mkdir -p /usr/local/mysql/data            //存放数据库

 

5.添加用户和创建数据库目录和权限设置

#groupadd mysql

#useradd -r -g mysql mysql

 

6.MYSQL 5.7.13安装

 

#cd  /usr/local

#wget http://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

#tar zvxf boost_1_59_0.tar.gz

#mv boost_1_59_0  boost

#cd /opt

#wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

# tar zxvf mysql-5.7.13.tar.gz

# cd mysql-5.7.13

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=/usr/local/boost

# gmake

# gmake install

 

参数说明:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql       //安装目录

-DINSTALL_DATADIR=/usr/local/mysql/data         //数据库存放目录

-DDEFAULT_CHARSET=utf8                     //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci          //校验字符

-DEXTRA_CHARSETS=all                        //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1                  //允许从本地导入数据

注意事项:

重新编译时,需要清除旧的对象文件和缓存信息。

# make clean

# rm -f CMakeCache.txt

# rm -rf /etc/my.cnf

# cd /usr/local/mysql

 

7.配置

(1)设置目录权限

# cd /usr/local/mysql

# chown -R root:mysql . //把当前目录中所有文件的所有者设为root,所属组为mysql

# chown -R mysql:mysql data

(2) 启动服务添加到系统

# cp  support-files/my-default.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中

(3)创建系统数据库的表

# cd /usr/local/mysql

# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

(4)设置环境变量

# vi /root/.bash_profile

在PATH=$PATH:$HOME/bin添加参数为:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

#source /root/.bash_profile

(5)启动mysql

# cd /usr/local/mysql

 

# cp support-files/mysql.server  /etc/init.d/mysql //将mysql的启动服务添加到系统服务中

# chkconfig --add mysql # 添加到系统服务

# chkconfig mysql on # 开机启动

# service mysql start

 

# ln -s /usr/local/mysql/bin/mysql /usr/bin

 ————————设置账号————————————

[root@gj mysql]# mysql -u root -p

 

Enter password:   初始密码为空,回车

 

mysql> set password for root@localhost = password('123456');

 

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

mysql> update user set host = '%' where user = 'root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

mysql> flush privileges;

 

Query OK, 0 rows affected (0.00 sec)

 

mysql> select host, user from user;

+-----------+-----------+

| host      | user      |

+-----------+-----------+

| %         | root      |

| localhost | mysql.sys |

+-----------+-----------+

 

2 rows in set (0.00 sec)

 

 

 

set global max_allowed_packet = 2*1024*1024*10;

 

------------------------------------------安全设置--------------------------------------

创建数据库:

 

create database 数据库名 default charset utf8 collate utf8_general_ci;

 

 创建一个最小权限的用户test

create user 'test'@'%' IDENTIFIED by '123456';

grant select,insert,update,delete,create,drop,alter on 数据库名.* to 'test'@'%';

grant lock tables on 数据库名.* to 'test'@'%';

flush privileges;

 

修改root用户名和密码,限制远程访问

update mysql.user set user="admin" where user="root";

flush privileges; 

update user set host='localhost' where user='admin';

flush privileges;//只允许root在本机登录

SET PASSWORD FOR 'admin'@'localhost' = PASSWORD('复杂的密码');

flush privileges; 

 

 

 

 

 

 

 

你可能感兴趣的:(mysql,centos,MySQL,linux)