linux7.5mysql安装教程,Linux(CentOS7.5)⼿动安装
Mysql5.7.28
Linux⼿动安装mysql5.7.28
⼀、下载
1.进⼊到 MySQL 官⽹下载⾃⼰对应版本的MySQL
⼆、配置环境
1、安装前检查
1.1、检查系统是否有⾃带安装MySQL
rpm -qa | grep mysql
如果有类似于
mysql-libs-5.1.52-1.el6_0.1.x86_64
可以选择进⾏卸载:
// 普通删除模式
rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64
// 强⼒删除模式,如果使⽤上⾯命令删除时,提⽰有依赖的其它⽂件,则⽤该命令可以对其进⾏强⼒删除
rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
1.2、检查是否存在 MariaDB 数据库:
rpm -qa | grep mariadb
如果有类似于linux mysql教程视频
mariadb-libs-5.5.56-2.el7.x86_64
选择进⾏卸载:
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
2、进⼊安装包所在⽬录,解压⽂件
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_
3、将解压好的⽂件夹移动到⾃⼰要安装的⽬录下并重新命名
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
cp -R mysql-5.7.28 /home/mysql-5.7.28
4、添加系统 MySQL 组合 MySQL ⽤户
4.1、检查 MySQL 组合⽤户是否存在,存在则⽆需创建
cat /etc/group | grep mysql
#类似
mysql:x:490:
cat /etc/passwd | grep mysql
#类似
mysql:x:496:490::/home/mysql:/bin/bash
4.2、如不存在则创建⽤户组
groupadd mysql
useradd -r -g mysql mysql
三、安装数据库
1、创建 data ⽬录
cd /home/mysql-5.7.28
mkdir data
2、修改安装⽬录权限
chown -R mysql:mysql /home/mysql-5.7.28
3、创建 myf ⽂件
cd support-files
vi myf
⽂件内容如下:
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /home/mysql-5.7.28
datadir = /home/mysql-5.7.28/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
# For advice on how to change settings please see
# *** 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.
log-error = /home/mysql-5.7.28/data/mysqld.log
pid-file = /home/mysql-5.7.28/data/mysqld.pid
4、拷贝myf⽂件到/etc⽬录下,如果提⽰是否覆盖,y
cp myf /etc/myf
5、初始化 mysqld
./bin/mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.28/ --datadir=/home/mysql-5.7.28/data/
如果这⾥报错如下:
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
则需要安装 numactl
yum -y install numactl
然后继续执⾏初始化mysqld命令
./bin/mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.28/ --datadir=/home/mysql-5.7.28/data/
6、初始化完成之后查看⽇志
tail -1000f /home/mysql-5.7.28/data/mysqld.log
⾃动⽣成的临时密码
2019-12-19T07:37:27.636655Z 1 [Note] A temporary password is generated for root@localhost: ebHONnAD:6(o 7、设置开机⾃起MySQL服务
7.1、创建systemctl管理mysql的配置⽂件命令:
touch /usr/lib/systemd/system/mysql.service
7.2、编辑该配置⽂件命令
vi /usr/lib/systemd/system/mysql.service
7.3、以下内容添加到配置⽂件中
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
# 此处注意mysql安装⽬录
ExecStart=/home/mysql-5.7.28/bin/mysqld --defaults-file=/etc/myf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false
7.4、启动 MySQL 服务
systemctl start mysql
7.5、查看MySQL服务状态:
ps -ef | grep mysql
7.6、通过systemctl 来设置mysql开机启动命令:
systemctl enable mysql
8、环境变量配置
vim /etc/profile
#最后⼀⾏添加:
export PATH=$JAVA_HOME/bin:/usr/local/mysql/bin:$PATH
#使修改⽣效:
source /etc/profile
9、登录 MySQL,密码为初始密码(如我的是:ebHONnAD:6(o)
cd /home/mysql-5.7.28
./bin/mysql -u root -p
10、修改密码
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
11、Mysql创建⽤户与授权,限制IP
11.1、创建⽤户
# CREATE USER ‘⽤户名’@‘限制的IP地址’ IDENTIFIED BY ‘密码’;
CREATE USER 'test'@'localhost' IDENTIFIED BY '123456';
11.2、授权
GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
#GRANT ALL ON *.* TO 'pig'@'%';
FLUSH PRIVILEGES;#不重启MySQL服务的情况下直接⽣效
#privileges:⽤户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使⽤ALL #databasename:数据库名
#tablename:表名,如果要授予该⽤户对所有数据库和表的相应操作权限则可⽤表⽰,如.*
11.3、设置与更改⽤户密码
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
11.4、撤销⽤户权限
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
11.5、删除⽤户
DROP USER 'username'@'host';
11.6、限制ip访问
use mysql;
update user set host = '172.0.0.1' where user = 'root' and host = '%'; FLUSH PRIVILEGES;
12、数据库导⼊(⾃⼰备份.sql⽂件)
mysql> create database lutw;
mysql> use lutw;
mysql> source /home/lutw.sql;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论