第一步下载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
方法一:手动启动
首先把脚本复制到linux的/etc/init.d/ 目录下,然后把MysqL.server重命名为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目录,或者写上路径名
或者
[[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 ‘********‘;