解压包安装方式
一、安装向导
1.系统约定
安装文件下载目录:/data/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql
2.下载mysql
在官网:http://dev.mysql.com/downloads/mysql/中,选择以下版本的mysql下载,完成后执行以下解压命令:
tar -zxf mysql-5.7.16-linux-glibc2.5-i686.tar.gz
3.解压压缩包到目标位置
mkdir /usr/local/mysql
mv mysql-5.7.16-linux-glibc2.5-i686 /usr/local/mysql
4.创建数据仓库目录
mkdir –p /data/mysql
ls/data/
5.新建mysql用户、组及目录
groupadd mysql
useradd -g mysql mysql
6.改变目录属有者
chmod a+xrw /usr/local/mysql/
chmod a+xrw /usr/local/mysql
(上面授权mysql文件夹读写权限很重要,会直接导致mysql.sock文件能否正常生成)
cd /usr/local/mysql
chown -R mysql:mysql /data/mysql
chown –R mysql
chgrp –R mysql
chown -R mysql /data/mysql
7.配置参数
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
期间会出现一些缺少系统库的提示(请参考后面的常见错误处理)
此处需要注意记录生成的临时密码,如:YLi>7ecpe;YP
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
8.修改系统配置文件
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
修改以下内容:
basedir=/usr/local/mysql
datadir=/data/mysql
vim/etc/my.cnf
修改以下内容:
此处内容较多,具体可以参考附录里面的样式进行设置。
9.启动mysql
添加启动软连接:ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql (移除软连接:rm -rf /usr/bin/mysql)
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql--user=root –p--输入第6步生成的临时密码
(./bin/mysql-u root -p)
此处可能出现错误提示
错误提示:
ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决方法:
bin/mysql -hlocalhost -uroot -p #--输入第6步生成的临时密码
登录成功之后修改root密码
mysql>set password=password('123456');
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';
mysql>exit
10.添加系统路径
vi /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
11.配置mysql自动启动
chmod755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
二、常见错误处理
1.缺库
bash:/usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter: No such file ordirectory
yuminstall glibc.i686
errorwhile loading shared libraries: libstdc++.so.6: cannot open shared object file:No such file or directory
yuminstall libstdc++.so.6
errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory
yum install libaio*
error while loading shared libraries: libncurses.so.5: cannot open shared object file
yum install libncurses.so.5
2. 解决Navicat 报错:1130-host is not allowed MySQL不允许从远程访问的方法
1. /usr/local/mysql/bin/>mysql -h localhost -u root -p //这样应该可以进入MySQL服务器
2. mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //赋予任何主机访问数据的权限
3. mysql>FLUSH PRIVILEGES; //修改生效
4. mysql>exit //退出MySQL服务器
3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/tmp/mysql.sock'
a.查看是否开启服务
# ps -ef | grep mysql
root 5605 5457 0 11:45 pts/2 00:00:00 grep mysql
b.查看my.cnf (参考附录重新编辑配置文件)
c.启动mysql服务器
# ./mysqld --defaults-file=/etc/my.cnf --user=root &
d .查看是否开启服务
# ps -ef | grep mysql
root 5359 1 0 11:42 ? 00:00:00 ./mysqld --defaults-file=/etc/my.cnf --user=root
root 5605 5457 0 11:45 pts/2 00:00:00 grep mysql
三、附录
1. my.conf配置内容参考
# For advice on how to changesettings please see
#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It'sa template which will be copied to the
# *** default location duringinstall, and will be replaced if you
# *** upgrade to a newer versionof MySQL.
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
#character-set-server = utf8
[mysql]
no-auto-rehash
[mysqld]
# Remove leading # and set to theamount of RAM for the most important data
# cache in MySQL. Start at 70% oftotal RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on avery important data integrity option: logging
# changes to the binary logbetween backups.
# log_bin
# These are commonly set, removethe # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
# server_id = .....
socket = /usr/local/mysql/mysql.sock
# Remove leading # to set optionsmainly useful for reporting servers.
# The server defaults are fasterfor transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
join_buffer_size = 64M
sort_buffer_size = 16M
read_rnd_buffer_size = 2M
#lower_case_file_system = ON
#lower_case_table_names = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
RPM方式安装
一、环境准备
1.官方下载地址:
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
2.解压:
tar -xvf mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar
3.卸载之前的版本
rpm -qa | grep -i mysql
rpm -e xxxxx [之前安装的版本] --nodeps 要卸载的mysql版本
4.安装依赖组件
yum -y install libaio / yum install libaio*
yum -y install net-tools
yum -y install perl
yum -y install libaio.so.1
二、按照步骤安装应用
1.rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm --nodeps --force
2.rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm --nodeps --force
3.rpm -ivh mysql-community-devel-5.7.20-1.el6.x86_64.rpm --nodeps --force
4.rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm --nodeps --force
5.rpm -ivh mysql-community-server-5.7.20-1.el6.x86_64.rpm --nodeps --force
三、查看、启动、停止数据库
# 查看mysql是否启动service
mysqld status
或者
service mysql status
# 启动mysqlservice
mysqld start
或者
service mysql start
# 停止mysqlservice
mysqld stop
# 重启mysqlservice
mysqld restart
四、修改密码 (有点特殊 )
1.查看临时密码
grep password /var/log/mysqld.log
服务器回应:
2017-09-01T16:43:10.889769Z 1 [Note] A temporary password is generated for root@localhost: hcLMTxbOh2?w
这样我们得知临时密码是:hcLMTxbOh2?w
2. 修改密码
# 登录mysql,之后需要输入密码
mysql -p
# 设置新密码(数据库的密码需要满足以下条件:大小写字母,数字和特殊符号)
set password = password("Mysql_123456");
# 退出当前登录
quit;
3.测试
mysql -uroot -p
enter password:Mysql_123456
五、异常处理
1. 登录异常:Can't connect to local MySQL server through socket '/tmp/mysql.sock'
[root@localhost /]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
#我们需要修改my.cnf文件
[root@localhost /]# vi /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
……
保存之后即出,重新启动mysql...