Linux 安装Mysql 5.7

 

下载Mysql
解压mysql压缩包
tar -xvzf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 
新建mysql 目录
mkdir /usr/local/mysql
拷贝解压文件到mysql 目录
mv mysql-5.7.22-linux-glibc2.12-x86_64/ /usr/local/mysql
创建data目录
cd /usr/local/mysql/
mkdir data
mkdir ./data/mysql
创建数据仓库目录
mkdir /data
mkdir /data/mysql
修改目录权限
cd /usr/local/mysql
chown -R mysql:mysql ./
chown -R mysql:mysql /data/mysql
安装数据库
./mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql
注意需要保存此处的随机密码,后面会用到。
拷贝my_default.cnf
cp my-default.cnf /etc/my.cnf
拷贝mysql.server
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动Mysql
/etc/init.d/mysql start 
创建启动链接
ln -s /usr/local/mysql/bin/mysql /usr/bin
登入MySql重置root密码,此处登入密码为上面步骤生成的随机密码
mysql -uroot -p
mysql> set password=password('root');
--设置root账户的host地址(修改了才可以远程连接)
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql>flush privileges;
添加系统路径
vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
配置mysql自动启动
# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql

至此Mysql5.7已安装完成。

在安装过程中可能会遇到如下问题:
一、mysql 5.7 默认没有my_default.cnf,可以使用如下文件

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
# 一般配置选项
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
[client]
/bin/bash: Q: command not found

二、启动的时候报ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
解决:创建一个软链接 ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.