一、下载
1.打开mysql官网:https://dev.mysql.com/
2.点击downloads--community--左侧选择MySQL Community Server
3.选择运行平台,下载安装包
二、解压
# tar -xvf /opt/mysql-5.7.17-linux-glibc2.5-x86_64.tar
# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
修改目录名称
# mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql
创建安装目录
创建软连接
# cd /usr/local
#ln -s /opt/mysql mysql
创建数据库保存位置
# mkdir /data/mysql
创建mysql用户,组
# groupadd mysql
# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql ---新建msyql用户禁止登录shell
改变目录所有者
# cd /usr/local/mysql
# chown -R mysql .
# chgrp -R mysql .
# chown -R mysql /data/mysql
配置参数
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
保存执行后的显示的密码:A temporary password is generated for root@localhost: YoiDx?-P:2Tp
# bin/mysql_ssl_rsa_setup --datadir=/data/mysql
修改系统配置文件
# cp support-files/my-default.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysql
# vim /etc/init.d/mysql
--------------------------------
basedir=/usr/local/mysql
datadir=/data/mysql
--------------------------------
# vim /etc/my.cnf(配置如下)
启动mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# /usr/local/mysql/bin/mysql --user=root –p
sql>set password=password('root');
sql>GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
sql>flush privileges;
my.cnf
--------------------------
[mysqld]
datadir=/data/mysql
socket=/usr/local/mysql/mysql.sock
basedir=/usr/local/mysql
user=mysql
port = 3306
character-set-server = utf8
explicit_defaults_for_timestamp = true
skip-ssl
secure-file-priv=NULL
[client]
socket=/usr/local/mysql/mysql.sock
port =3306
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set =utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
三、配置
四、解决问题
1.输入密码时出现:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql.sock' (111)
解决办法:首先查看错误日志有无error记录,若有,根据错误解决即可
使用命令查看sock生成位置: find / -name *mysql.sock 然后在my.cnf的[client]下写入
[client]
socket=/var/lib/mysql/mysql.sock
重启即可。
2.修改密码时出现:
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
解决办法:
mysql>update mysql.user set authentication_string=password('asdf') where user='root' and Host ='localhost';
mysql>SET PASSWORD = PASSWORD('asdf');
3.没有远程访问权限:
Access denied for user 'root'@'192.168.1.14' (using password: YES)
解决办法:
root默认只有本机访问的权限,要通过其他机器访问,必须授权
GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
4设置字符集
修改my.cnf文件
1、在[client]字段里加入
default
-
character
-
set
=utf8,如下:
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default
-
character
-
set
=utf8
2、在[mysqld]字段里加入
character
-
set
-server=utf8,如下:
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character
-
set
-server=utf8
3、在[mysql]字段里加入
default
-
character
-
set
=utf8,如下:
[mysql]
no
-auto-rehash
default
-
character
-
set
=utf8
http://www.jb51.net/article/90317.htm