软件下载地址:
mysql安装步骤:
1,首先下载安装包(cd /usr/local)报错忽略即可
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar
2,解压到user/local路径下
tar xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar -C /usr/local/
3,将解压的文件在进行解压
tar xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
4,移动解压文件且修改文件夹名为 mysql
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
5,在mysql文件夹下创建数据文件目录
mkdir mysql/data
6,创建mysql用户和组
groupadd mysql
useradd mysql -g mysql
chmod -R mysql .(进入mysql目录执行)
chgrp -R mysql . (进入mysql目录执行)
7,开始进行安装(因mysql需要libaio支持,所以需要先安装libaio库)
yum install libaio
8,进入到bin目录执行(/usr/local/mysql/bin)
./mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
9,启动完成进行登录mysql (需要先修改初始密码)
cat /root/.mysql_secret
10,开始连接mysql(使用上一步查询到的密码)
mysql -u root -p
11,建立连接软连接(使用mysql -u root -p报错时候需要先执行11步骤,否则不执行)
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
12,连接到mysql修改root密码
update mysql.user set authentication_string=password('123456') where user='root'; 刷新权限:flush privileges
13,检查安装路径下 /usr/local/mysql/support-files 是否存在my-default.conf文件(没有需要创建一个)
vim my-default.conf 将下方文件放入进去即可
# 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]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
#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
connect_timeout=2
[client]
port=3306
socket = /tmp/mysql.sock
14,拷贝一个文件方便启动
cp my-default.cnf /etc/my.cnf
15,将mysqld服务设置为开机启动项(support-files/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld)
cp mysql.server /etc/init.d/mysqld
16,通过chkconfig命令将mysqld服务加入到自启动服务项中
chkconfig --add mysqld
chkconfig list
17,可以直接在系统执行命令启停mysql服务
service mysqld restart 重启
service mysqld start 启动
service mysqld stop 停止
netstat -anp|grep 3306 查看进程
18,设置远程登录mysql
修改mysql库的user表,将host项,从localhost改为%。(%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip)
use user; 切换用户
select user,host from user; 查询连接方式
update user set host = '%' where user = 'root'; 修改root外部连接
grant ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';外部连接授权
19,可添加网络限制端口,在etc/sysconfig 中编辑iptables :
添加端口:-A INPUT -m state --state NEW -m tcp --dport 3306 -j ACCEPT