Centos 6.5安装mysql

转载自:https://www.cnblogs.com/leffss/p/8512773.html

一.安装前准备

安装采用二进制包方式,软件包5.7.19版本下载地址:https://dev.mysql.com/downloads/mysql/

选择MYSQL Community Server版本再根据操作系统和版本选择性下载

 

二.解压安装

1.创建mysql用户

[root@server ~]# useradd -s /sbin/nologin mysql

 

2.解压安装

[root@server ~]# tar xvf mysql-5.7.19.tar.gz

[root@server ~]# /bin/mv –f mysql-5.7.19 /usr/local/mysql

[root@server ~]# mkdir /data/mysql_data

[root@server ~]# chown mysql. -R /usr/local/mysql /data/mysql_data

[root@server ~]# cp /usr/loca/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@server ~]# chmod a+x /etc/init.d/mysqld

[root@server ~]# chkconfig --add mysqld

[root@server ~]# chkconfig mysqld on

[root@server ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

 

3.初始化mysql

/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql_data  --user=mysql

初始化成功后会得到一个随机的初始化root密码显示在控制台,如果控制台没有显示,请在/var/log/message日志中查找,保存待用

 

4.设置mysql配置文件

[root@server ~]# vi /etc/my.cnf

[client]

port=3306

default-character-set=utf8

 

[mysqld]

datadir=/data/mysql_data

user=mysql

port=3306

character-set-server='utf8'

collation-server='utf8_general_ci'

skip-external-locking

key_buffer_size = 16M

wait_timeout=2880000

interactive_timeout = 2880000

max_allowed_packet = 1024M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

max_connections=1024

max_connect_errors=20000

#innodb_additional_mem_pool_size=4M

innodb_flush_log_at_trx_commit=2

innodb_log_buffer_size=256M

innodb_buffer_pool_size=256M

innodb_autoextend_increment=128

innodb_log_file_size=256M

innodb_thread_concurrency=8

innodb_flush_method=O_DIRECT

thread_cache_size=8

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

 

注:此配置仅供参考,不同主机根据主机配置以及需求做配置

 

三.启动mysql

1.启动

[root@server ~]# service mysqld start

 

2.登陆mysql配置root密码

使用初始化时随机分配的root密码登陆,并修改root密码,如不修改,无法做任何数据操作。

[root@server ~]# mysql –uroot –p

mysql > SET PASSWORD = PASSWORD('123456');            #设置新root密码

mysql > ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

mysql > flush privileges;

 

至此,mysql安装完成

posted @ 2018-06-19 14:39  Presley  阅读(182)  评论(0编辑  收藏  举报