linux下mysql的安装

一、环境

1、centos6.5-64位

  mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

二、安装(上传、解压、指定用户、创建mysql目录、权限)

创建目录mkdir -p/opt/mysql

进入目录cd /opt/mysql

解压mysql安装包tar zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

创建软连接:ln -s /opt/mysql-5.7.14-linux-glibc2.5-x86_64 /usr/local/mysql
创建用户:groupadd mysql
指定用户:useradd -M -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
创建基本目录:mkdir -p /data/mysql/mysql3306/{data, logs, tmp}
更改属主:chown -R mysql:mysql /data/mysql/mysql3306
创建my.cnf文件放在:/etc/my.cnf

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8
default_storage_engine = innodb
log_timestamps = SYSTEM
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mysql/data
pid-file=/mysql/data/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_force_recovery=1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend

#####====================================[log]==============================
log_error = /mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql/log/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
~

指定配置文件初始化: ./bin/mysqld --defaults-file=/etc/my.cnf --initialize
创建启动脚本:cd /usr/local/mysql/
cp support-files/mysql.server /etc/init.d/mysql
注意:5.7 初始化会加一个默认的密码,存放在error log里面,/data/mysql/mysql3306/data/error.log
在error.log中过滤出密码:cat /data/mysql/mysql3306/data/error.log |grep password  按照这样可以得到密码
2016-08-03T01:57:04.398037Z 1 [Note] A temporary password is generated for root@localhost: Fb&CYhv6UlwP
密码就是: Fb&CYhv6UlwP

修改目录权限
chown -R mysql:mysql /usr/local/mysql /mysql
配置启动文件
cp support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
service mysql start
配置环境变量
mysql_home=/usr/local/mysql
PATH=$PATH:$mysql_home/bin
source /etc/profile
启动数据库
service mysql start、

停止数据库

mysql stop

重新启动数据库

service mysqlrestart

进入数据库

mysql -uroot

 

 

 
posted @ 2017-11-29 16:47  raner  阅读(226)  评论(0编辑  收藏  举报