CentOS6.x 下 LNMP环境搭建(一、安装 MySQL)

前端之家收集整理的这篇文章主要介绍了CentOS6.x 下 LNMP环境搭建(一、安装 MySQL)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS6.x 下 LNMP环境搭建(准备篇)

CentOS6.x 下LNMP环境搭建(一、安装 MysqL

CentOS6.x 下LNMP环境搭建(二、安装 Nginx

CentOS6.x 下LNMP环境搭建三、安装 PHP

1. 创建用户

# groupadd MysqL
# useradd -s /sbin/nologin -g MysqL -M MysqL

---- 检查----
# tail -1 /etc/passwd
MysqL:x:501:501::/home/MysqL:/sbin/nologin
# id MysqL
uid=501(MysqL) gid=501(MysqL) groups=501(MysqL)
---- 检查 ----
注:也可以用一条命令代替【useradd MysqL -s /sbin/nologin -M】

2. 解压、配置

# cd /root/src
# tar -zxvf MysqL-5.5.50-linux2.6-x86_64.tar.gz
# mv MysqL-5.5.50-linux2.6-x86_64 /lnmp/server/MysqL-5.5.50 && cd /lnmp/server
# ls -l
# ln -s /lnmp/server/MysqL-5.5.50/ MysqL
# ls -l
# cd MysqL
# ls -l support-files/*.cnf  <------- 查看所有配置样例
# /bin/cp support-files/my-large.cnf /etc/my.cnf  <------- /bin/cp 直接覆盖重名文件,不提示

3. 初始化数据(是否需要单独挂一个目录?根据需要)

# mkdir -p /data/MysqL
# chown -R MysqL:MysqL /data/MysqL
# ./scripts/MysqL_install_db --basedir=/lnmp/server/MysqL --datadir=/data/MysqL --user=MysqL
...
Installing MysqL system tables...
160529 18:23:19 [Note] /lnmp/server/MysqL/bin/MysqLd (MysqLd 5.5.50) starting as process 33182 ...
OK
Filling help tables...
160529 18:23:20 [Note] /lnmp/server/MysqL/bin/MysqLd (MysqLd 5.5.50) starting as process 33189 ...
OK

To start MysqLd at boot time you have to copy
support-files/MysqL.server to the right place for your system
...


注:如上出现两个ok,标识初始化成功;否则失败,需解决初始化错误

4.修改设置并启动服务

# cp ./support-files/MysqL.server /etc/init.d/MysqLd
# chmod 755 /etc/init.d/MysqLd
# sed -i 's#/usr/local/MysqL#/lnmp/server/MysqL#g' /lnmp/server/MysqL/bin/MysqLd_safe /etc/init.d/MysqLd
  <------- 替换二进制包的默认MysqL安装路径
# vim /etc/init.d/MysqLd  <------- 修改 basedir 和 datadir,如下
basedir=/lnmp/server/MysqL
datadir=/data/MysqL
# /etc/init.d/MysqLd start <------- 启动服务
Starting MysqL... SUCCESS!

检查 3306 是否启动:
# netstat -tlunp|grep MysqL
tcp    0   0 0.0.0.0:3306   0.0.0.0:*   LISTEN   33457/MysqLd

5. 设置开机自启动

# chkconfig --add MysqLd
# chkconfig MysqLd on
# chkconfig --list|grep MysqLd
MysqLd     0:off  1:off  2:on  3:on  4:on  5:on  6:off

6. 配置MysqL命令全局使用

# echo 'export PATH=/lnmp/server/MysqL/bin:$PATH' >>/etc/profile
# tail -1 /etc/profile <------- 检查写入文件
export PATH=/lnmp/server/MysqL/bin:$PATH
# source /etc/profile  <------- 使修改马上生效
# echo $PATH  <------- 检查最终设置结果
/lnmp/server/MysqL/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/whoru/bin

7. 登录测试,更改默认管理员密码

# MysqL   <------- 输入 MysqL 可以直接登录,安装好后默认密码为空
Welcome to the MysqL monitor. Commands end with ; or \g.
.....
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL>quit;   <------- 退出 MysqL 命令行
# MysqLadmin -u root password 'whoru123'  <------- 修改 root 默认的空密码
# MysqL
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# MysqL -uroot -p  <------- 必须使用用户名和密码登录
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
.....
MysqL>

8. 清理没有用的用户及库

MysqL> select user,host from MysqL.user;
+------+-----------+
| user | host   |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1    |
|   | localhost |
| root | localhost |
|   | web1   |
| root | web1   |
+------+-----------+
6 rows in set (0.00 sec)

MysqL> drop user "root"@"::1";
Query OK,0 rows affected (0.00 sec)

MysqL> drop user ""@"localhost";
Query OK,0 rows affected (0.00 sec)

MysqL> drop user ""@"web1";
Query OK,0 rows affected (0.00 sec)

MysqL> drop user "root"@"web1";
Query OK,0 rows affected (0.01 sec)

MysqL> select user,host from MysqL.user;
+------+-----------+
| user | host   |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)

MysqL> flush privileges;  <------- 清除缓存
Query OK,0 rows affected (0.00 sec)
原文链接:https://www.f2er.com/centos/380571.html

猜你在找的CentOS相关文章