一、环境配置
检测系统是否自带Mysql
# rmp -qa|grep mysql
如果有进行强行卸载
# rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
检测系统是否自带mariadb
# rpm -qa|grep mariadb
# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-server-5.5.64-1.el7.x86_64
二、用连接工具将下载的mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz上传到linux服务器/data/software/的目录下面
三、安装
1、进入/data/software/目录下解压
# tar -zxvf mysql-5.7.28.tar.gz
解压完成后重命名
# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
# mv mysql-5.7.28 /usr/local/
2、检查mysql组和用户是否存在,如果没有则创建
cat /etc/group|grep mysql
groupadd mysql
useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
四、安装数据库
1、创建data目录
cd /usr/local/mysql-5.7.28
mkdir data
2、将/usr/local/mysql-5.7.28的所有者及所属组改为mysql
# chown -R mysql.mysql /usr/local/mysql-5.7.28
3、在/usr/local/mysql-5.7.28/support-files目录下创建my_default.cnf
# vim my_default.cnf
[mysqld]
#设置mysql的安装目录
basedir =/usr/local/mysql-5.7.28
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql-5.7.28/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql-5.7.28/data/mysqld.log
pid-file = /usr/local/mysql-5.7.28/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[client]
default-character-set = utf8
[mysql]
auto-rehash
prompt = (\u@\h) [\d]>\_
default-character-set = utf8
4、拷贝,是否覆盖,是
# cp my_default.cnf /etc/my.cnf
5、初始化Mysql
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.28/ --datadir=/usr/local/mysql-5.7.28/data/
如果报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or 就安装libaio,如果没有则跳过
yum install libaio
6、初始化完成之后查看日志
cat /usr/local/mysql-5.7.28/data/mysqld.log,蓝框里的是临时密码
cat /usr/local/mysql-5.7.28/data/mysqld.log | grep password 查找密码
7、编辑/usr/local/mysql-5.7.28/upport-files/目录下的mysql.server文件,找到如下两行添加mysql的安装目录和数据存放目录
basedir=/usr/local/mysql-5.7.28
datadir=/usr/local/mysql-5.7.28/data
8、添加软连接,并重启mysql服务
把启动脚本放到开机自启目录
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
添加mysqld软链接到/usr/bin/,方便使用mysqld命令管理mysql的启停
ln -s /usr/local/mysql/support-files/mysql.server /usr/bin/mysqld
添加mysql软链接到/usr/bib/,方便使用mysql命令登录数据库
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
9、启动mysql
cd /var/local/mysql-5.7.28/support-files
./mysql.server start
或者使用mysqld命令启动
mysqld start
查看运行状态
mysqld status
10、登录mysql
cd /usr/local/mysql-5.7.28
./bin/mysql -u root -p
或者使用mysql命令登录
mysql -uroot -p
11、更改密码
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
12、添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
如果更改时报错:ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY',就先查询一下是否已更改,最后执行刷新。
数据导出导入
第一:建库
create database testdata;
create database testdata;第二:
导出
mysqldump -u query -pquery -R --databases testdata> expdp_testdata.sql
第三:导入
mysql -u query -pquery --default-character-set=utf8 testdata< expdp_testdata.sql
标签:5.7,安装,28,mysqld,usr,mysql,local From: https://www.cnblogs.com/teiperfly/p/18051151