安装
进入安装包所在目录,解压文件
cd /home tar -zxvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
重命名
mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql-5.7.13
添加系统mysql组和mysql用户
检查mysql组和用户是否存在,如无创建
cat /etc/group | grep mysql #类似 mysql:x:490: cat /etc/passwd | grep mysql #类似 mysql:x:496:490::/home/mysql:/bin/bash
以上为存在的情况,如无,执行添加命令:
groupadd mysql useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
安装数据库
创建data目录
cd mysql-5.7.13 mkdir data
将/home/mysql/mysql-5.7.13的所有者及所属组改为mysql
chown -R mysql.mysql /home/mysql-5.7.13
修改/home/mysql-5.7.13/support-files目录下配置文件my-default.cnf
并复制以下信息至my-default.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]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#lower_case_table_names=1
basedir = /home/mysql-5.7.13
datadir = /home/mysql-5.7.13/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /home/mysql-5.7.13/data/mysqld.log
pid-file = /home/mysql-5.7.13/data/mysqld.pid
拷贝,如果提示是否覆盖,y
cp support-files/my-default.cnf /etc/my.cnf
初始化 mysqld
cd /home/mysql-5.7.13 ./bin/mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.13/ --datadir=/home/mysql-5.7.13/data/
初始化完成之后,查看日志
/home/mysql-5.7.13/data/mysqld.log
临时密码
A temporary password is generated for root@localhost: Bjs!&sjbX9Kq
把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
启动mysql服务
service mysql start
创建软连接 ln -s /home/mysql-5.7.13/bin/mysql /usr/bin
登录mysql,密码为初始密码
cd /home/mysql-5.7.13 ./bin/mysql -u root -p
修改密码
mysql> set password=password('1234.ecp'); mysql> grant all privileges on *.* to root@'%' identified by '1234.ecp'; mysql> flush privileges;
添加远程访问权限
mysql> use mysql; mysql> update user set host='%' where user = 'root'; mysql> flush privileges;
重启mysql生效
service mysql stop
service mysql start
or
service mysql restart
mysql数据的导出和导入
cd /home/mysql-5.7.13/bin
导出整个数据库中的所有数据
./mysqldump -u userName -p dabaseName > fileName.sql
导出数据库中的某个表的数据
./mysqldump -u userName -p dabaseName tableName > fileName.sql
导出整个数据库中的所有的表结构
./mysqldump -u userName -p -d dabaseName > fileName.sql
导出整个数据库中某个表的表结构
./mysqldump -u userName -p -d dabaseName tableName > fileName.sql
导入mysql方法1
./mysql -uroot -p
source fileName.sql
导入mysql方法2
./mysql -uroot -p database < fileName.sql