linux mysql 5.7.18 安装及配置

1、创建mysql组和用户
#groupadd mysql
#cat /etc/group | grep mysql
#useradd -r -g mysql mysql
#cat /etc/passwd | grep mysql
2、下载最新版的MySQL 5.7.18二进制包,上传至服务器的usr/local目录下
3、解压:
#tar xcfz mysql-5.7.18-liunx-x86_64.tar.gz
4、更改所属的组和用户
local#chown -R mysql mysql/
local#chgrp -R mysql mysql/
5、查看support-files文件夹的内容,发现并没有my_default.cnf默认的配置文件,如果没有默认的配置文件,需要手动创建一个my_default.cnf配置文件
 
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#mysql连接速度慢 
skip-name-resolve
skip-grant-tables
# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /usr/local/mysql/mysqld.sock
character-set-server=utf8
#不区分大小写
lower_case_table_names=1
#下面是可选项,要不要都行,如果出现启动错误,则全部注释掉,保留最基本的配置选项,然后尝试添加某些配置项后启动,检测配置项是否有误
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]
port=3306
# socket=/usr/local/mysql/mysql.sock
socket = /usr/local/mysql/mysqld.sock
 
6、注册和初始化MySQL服务
  这一点比较坑,网上的教程大多是mysql_install_db 方式安装的,这一步也是遇到问题最最多的,折腾了好久,但是mysql_install_db 命令是不推荐的,也提示使用mysqld来安装,
在安装mysql 5.7.18的时候也是各种报错,经过各种尝试之后吧,采用如下命名方式安装,只要没有Error,警告信息Warning先不理它
先安装libaio
#rpm -i libaio-0.3.107-10.el6.x86_64.rpm,
mysql#bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/ 
 
7、复制上述的my_default.cnf和mysql.server配置文件到etc目录,之前复制过该文件到etc目录,它这里提示是否覆盖,输入Y覆盖
#cp -a /usr/local/mysql/supprot-files/my_default.cnf /etc/my.cnf
#cp -a /usr/local/mysql/supprot-files/mysql.server /etc/init.d/mysqld
 
8、启动MySQL服务
bin#./mysqld_safe --user=mysql
#/etc/init/d/mysqld restart
 
9、连接至MySQL,默认没有密码,直接回车后连接至MySQL
bin#./mysql -uroot -p
10、修改MySQL的root密码
mysql>set password=password('root');
11、修改可远程访问(权限不够时,先执行 SET SQL_SAFE_UPDATES = 0;)
mysql>set SQL_SAFE_UPDATES=0;
mysql>use mysql;
mysql>update user set host='%' where user='root';
12、重启MySQL服务
#/etc/init.d/mysqld restart
13、此时测试本地可以正常使用MySQL
14、在测试远程是否可以使用,如果防火墙问题,关闭防火墙:#service iptables stop 

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