linux(CentOS6.7) 环境 Mysql 5.7.17 安装教程分享给大家,供大家参考,具体内容如下:
1 系统约定
安装文件下载目录:/data/software
Mysql 目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql
2 下载 mysql
在官网:http://dev.mysql.com/downloads/mysql/ 中,选择以下版本的 mysql 下载:
执行如下命名:
#mkdir /data/software
#cd /data/software
--下载安装包
--建议:在 windows 上使用迅雷下载,速度很快(我的是 1M/s),然后用工具(Xftp)上传到 /data/software 目录下;
#wget
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
3 解压压缩包到目标位置
#cd /data/software
--解压压缩包
#tar -xzvf /data/software/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
--移动并修改文件名
#mv /data/software/mysql-5.7.17-linux-glibc2.5-x86_64
/usr/local/mysql
4 创建数据仓库目录
--/data/mysql 数据仓库目录
# mkdir /data/mysql
#ls /data/
5 新建 mysql 用户、组及目录
#
---新建一个 msyql 组
#groupadd mysql
#useradd -r -g mysql mysql
# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
---新建 msyql 用户禁止登录 shell
6 改变目录属有者
#cd /usr/local/mysql
#pwd
#chown -R mysql .
#chgrp -R mysql .
#chown -R mysql /data/mysql
7 配置参数
# yum install -y libaio
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
此处需要注意记录生成的临时密码,如上文结尾处的:YLi>7ecpe;YP
#bin/mysql_ssl_rsa_setup
--datadir=/data/mysql
8 修改系统配置文件
#cd
/usr/local/mysql/support-files
# cp my-default.cnf /etc/my.cnf
# cp mysql.server /etc/init.d/mysql
# vim /etc/init.d/mysql
修改以下内容:
9 启动 mysql
#{mysql}/bin/mysqld_safe&
把 mysql 注册为开机启动的服务
#chkconfig --add mysql
当然也可以手动进行服务的开启和关闭:
#/etc/init.d/mysql start
#/etc/init.d/mysql stop
如果文件 mysql.log 不存在,echo "" > /usr/local/mysql/mysqld.log
--登陆
#
mysql -hlocalhost -uroot -p
--如果出现:-bash: mysql: command not found
--就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin --没有出现就不用执行
--输入第 6 步生成的临时密码
此时要求输入密码,就是前面初始化时生成的密码。
这时如果连接服务的时候出现错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
则需要在在 my.cnf 中填加:
[client]
socket = /work/program/mysql/tmp/mysql.sock
--修改密码
mysql> set password=password('root');
--设置 root 账户的 host 地址(修改了才可以远程连接)
//将所有数据库的所有表(*.*)的所有权限(all privileges),授予通过任何ip(%)访问的root用户,密码为 root,如
果要限制只有某台机器可以访问,将其换成相应的IP即可
mysql>grant all privileges on *.* to 'root'@'%'
identified by 'root';
mysql>flush privileges;
--查看表
mysql> use mysql;
mysql> select host,user from user;
--这里就可以使用远程连接测试了;
10 添加系统路径
# vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
如下:
# source /etc/profile
11 配置 mysql 自动启动
# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --level 345 mysql on
以上就是 linux 环境 Mysql 5.7.13 安装教程,希望对大家的学习有所帮助。
补充:
--退出 mysql 命令窗口
#exit
--查看 mysql 状态
#service mysql status
--停止 mysql
#service mysql stop
--启动 mysql
#service mysql start
附 my.cnf(这是一个配置 mysql 配置文件,暂时可以不用管,如你想钻研 你可以百度或 google “mysql my.cnf 配置详情”)
/etc/my.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]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 10G
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin
character-set-server=utf8
collation-server=utf8_bin
init-connect='SET NAMES utf8'
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /export/mysql/var
port = 3306
server_id = 22206
socket = /export/mysql/mysql.sock
binlog_format = statement
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
文档参考:http://www.cnblogs.com/zhao1949/p/5947938.html
Centos7.4 修改 MySQL5.7 root 密码
参考博文:
http://www.jb51.net/article/100211.htm
https://www.cnblogs.com/wangbaobao/p/7087032.html
1.vim /etc/my.cnf
2.在[mysqld]中添加
skip-grant-tables
例如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
3.重启 mysql
service mysql restart
4.用户无密码登录
mysql -uroot -p (直接点击回车,密码为空)
5.选择数据库
use mysql;
6.修改 root 密码
(5.7.9 以前的版本)
UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
完成--------------
(5.7.9 以后的版本)
1、先将密码设置为空
use mysql;
update user set authentication_string='' where user='root'
2、quit; 退出 mysql ;
vim /etc/my.cnf 将 skip-grant-tables 删除,保存退出;
service mysql restart 重启 mysql;
3、登录:mysql -uroot -p , 因为密码为空,所以可以直接回车,登录成功;
4、正式修改密码:
ALTER user 'root'@'localhost' IDENTIFIED BY 'Qian123#';
至此修改成功; 从新使用用户名密码登录即可;
7.执行
flush privileges;
8.退出 mysql
quit
9.编辑 /etc/my.cnf
删除 skip-grant-tables 保存退出
10.重启 mysql
service mysql restart