-
解压
.tar.gz后缀:tar -zxvf 文件名
.tar.xz后缀:tar -Jxvf 文件名
-
重命名文件并移动
mv 解压后文件名 mysql
mv mysql /usr/local/
cd /usr/local/m
-
创建用户组和用户
groupadd mysql
useradd -r -g mysql mysql
-
创建MySQL数据目录
mkdir /usr/local/mysql/data
-
进入mysql目录对文件赋予权限
cd /usr/local/mysql/
chown -R mysql:mysql ./
-
初始化数据库
进入mysql下的bin目录
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
初始化后会生成一个初始密码 ,输出中 root@localhost: =7j1kzPnD<p; 中的字符’=7j1kzPnD<p;'即为初始密码,每个人的都不一样,修改密码要用到,如果忘记了找不回来了,删除data目录下的所有文件,重新初始化一次。
在bin下创建这个文件,并且配置权限,修改当前用户为root用户
cd /usr/local/mysql/bin
mkdir mysql_install_db
chmod 777 ./mysql_install_db
-
编辑my.cnf文件
退回mysql目录,创建my.cnf文件
touch my.cnf
vim my.cnf
按 i 键进行编辑,编辑完后按Esc退出编辑,shift + :后输入指令wq,进行保存修改退出文件或退出或退出不修改(:wq -->保存并退出,:q–>退出,:q! -->不保存退出),内容为:
[mysql]
default-character-set=utf8mb4
[client]
port = 3306
socket = /usr/local/mysql/tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /usr/local/mysql/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
character-set-server=utf8mb4
autocommit =1
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
binlog_format=mixed
binlog_expire_logs_seconds =864000
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
修改权限:
chown -R root:root ./
chown -R mysql:mysql data
如果/usr/local/mysql/目录下没有tmp文件,手动创建,并且配置权限:
cd /usr/local/mysql/
mkdir tmp
chmod 777 ./tmp
-
加入开机自启
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
-
注册启动服务
chkconfig --add mysql
chkconfig --list mysql
-
配置环境变量
vim /etc/profile
末尾追加以下代码
export MYSQL_HOME
MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/lib:$MYSQL_HOME/bin
执行环境变量
source /etc/profile
-
启动服务
service mysql start