Linux环境下java开发环境搭建三 mysql解压安装(预编译安装)

第一步下载linux环境下的安装包,并把安装包解压到/usr/local/目录下

分享图片

解压后的文件如下

分享图片

第二步:安装前的一些准备工作

(1)建立软链接

#ln  -s MysqL-5.7.25-linux-glibc2.12-x86_64   MysqL

(2)创建MysqL组与MysqL 用户

#groupadd msyql

创建的MysqL用户不能登录只是用来启动MysqL数据库,且其家目录为/usr/local/MysqL,并不是/home/MysqL

#useradd -r -s /sbin/nologin -g MysqL MysqL -d /usr/local/MysqL

(3)在/user/local/目录下创建MysqL-files目录,且赋予750权限

#mkdir MysqL-file

#chmod 750 MysqL-files

分享图片

 

(4)把/user/local/MysqL目录的所属用户设置成MysqL用户,所属组都设置成MysqL

分享图片

 

第三步:MysqL的安装

(1)使用/usr/local/MysqL/bin目录下的MysqLd进行初始化

[[email protected] MysqL]# bin/MysqLd --initialize --user=MysqL --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data

--user=MysqL                                  代表初始化时,使用的linux用户MysqL用户

--basedir=/usr/local/MysqL             代表MysqL安装的目录是/usr/local/MysqL

--datadir=/usr/local/MysqL/data      代表MysqL以后的数据库都存放在/usr/local/MysqL/data

注意的一点就是如果/etc/my.cnf文件存在,一些配置信息会读取这个配置文件中的内容,如果在这文件中配置了 log-error ,那么MysqL的初始化过程不会打印到标准输出中,而是输出到log-error配置的文件中。初始化中会给出一个root的初始化密码,要记住

分享图片

(2)在/etc/目录下创建配置文件,/etc/my.cnf

[MysqLd]
basedir=/usr/local/MysqL
datadir=/usr/local/MysqL/data
user=MysqL
# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-storage-engine=InnoDB
innodb-file-per-table=1
character_set_server=utf8mb4

[MysqLd_safe]

[client]
default-character-set=utf8mb4

(3)启动MysqL

方法一:手动启动

#MysqLd_safe   --user=MysqL &

方法二:使用安装包中的MysqL.server脚本启动

首先把脚本复制到linux的/etc/init.d/  目录下,然后把MysqL.server重命名MysqLd

分享图片

重命名后的MysqLd设置成开机启动

分享图片

 

[[email protected] MysqL]# cp ./support-files/MysqL.server /etc/init.d/
[[email protected] MysqL]# mv /etc/init.d/MysqL.server /etc/init.d/MysqLd
[[email protected] MysqL]# chkconfig --add MysqLd
[[email protected] MysqL]# chkconfig MysqLd on

启动MysqL

[[email protected] MysqL]# service MysqLd start
Starting MysqL.Logging to /usr/local/MysqL/data/slave1.err.
 SUCCESS!

查看一些MysqLd的启动情况

[[email protected] MysqL]# ps aux| grep MysqLd
root      1689  0.1  0.1  11436  1540 pts/2    S    18:12   0:00 /bin/sh /usr/local/MysqL/bin/MysqLd_safe --datadir=/usr/local/MysqL/data --pid-file=/usr/local/MysqL/data/slave1.pid
MysqL     1861  4.0 17.6 1168192 180332 pts/2  Sl   18:12   0:00 /usr/local/MysqL/bin/MysqLd --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data --plugin-dir=/usr/local/MysqL/lib/plugin --user=MysqL --log-error=slave1.err --pid-file=/usr/local/MysqL/data/slave1.pid
root      1891  0.0  0.0 103248   868 pts/2    S+   18:12   0:00 grep MysqLd

可以看到,其实采用脚本启动调用的也是MysqLd_safe命令

(4)把/usr/local/MysqL/bin目录加入到linux的PATH变量,这样在使用/usr/local/MysqL/bin目录下的命令时,就不需要进入到bin目录,或者写上路径名

export MysqL_HOME=/usr/local/MysqL/
export PATH=$PATH:$MysqL_HOME/bin

或者

[[email protected] MysqL]# echo "export PATH=$PATH:/usr/local/MysqL/bin" >> /etc/profile

(5)使/etc/profile 配置文件重新生效

[[email protected] MysqL]# source /etc/profile

 

(6) 此时就可以登录通过 #MysqL -uroot -p‘密码登录

[[email protected] MysqL]# MysqL -uroot -p
Enter password: 
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 2
Server version: 5.7.25

copyright (c) 2000,2019,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

首次登录需要重置密码

MysqL> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
MysqL> alter user [email protected]localhost identified by ‘********;

通过alter语句对密码进行重置,密码要复核一些原则,数字,字母,大小写,特殊字符等.

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...