LNMP开发环境搭建——MySql安装管理

2016-6-30 邪哥

CentOS 6.5 x86_64  安装MySql 5.6.31

老话回顾,请留意过程中的文字说明,已经脚本样例过程中的 #注释文字

下载地址

http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz

[root@localhost ~]# cd soft/ 
[root@localhost soft]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
[root@localhost soft]# cd /usr/local/
[root@localhost local]# tar -zxvf ~/soft/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 
[root@localhost local]# mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql/
[root@localhost local]# cd mysql/
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# chown -R mysql:mysql ./ 
[root@localhost mysql]# scripts/mysql_install_db --user=mysql 
[root@localhost mysql]# chown -R root ./ 
[root@localhost mysql]# chown -R mysql data/ 
#备份系统默认的配置文件
[root@localhost mysql]# mv /etc/my.cnf /etc/my.cnf.bak
#将自动生成的配置文件拷贝到系统配置目录
[root@localhost mysql]# cp my.cnf /etc/my.cnf 
#将服务管理文件拷贝至系统对应目录
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld 
到这边其实MySQL的安装已经算是结束了,使用的配置文件,服务管理脚本均为默认及自带内容

关于mysql配置项调优及具体说明,这边就不做介绍了

但是我们还没启动 并 测试连接呢,那么咱们接着来

#先按初始化给出的提示 进行启动
[root@localhost mysql]# ./bin/mysqld_safe & 
#启动成功之后  再使用 service mysqld 进行管理
[root@localhost mysql]# service mysqld status
MySQL running (3479)                                       [确定]
[root@localhost mysql]# service mysqld restart
Shutting down MySQL..                                      [确定]
Starting MySQL.                                            [确定]
#到这里 说明已经成功了,今后就可以使用 service mysqld 进行服务管理了
再接着就是测试连接了,在测试连接之前,咱们先去修改下环境变量,方便日后使用
[root@localhost mysql]# vi /etc/profile 
#切换到文件底部,找到之前添加的nginx 环境变量,在后面补充完善如下
PATH=/usr/local/nginx/sbin:/usr/local/mysql/bin:$PATH
export PATH
#完成后保存退出

[root@localhost mysql]# source /etc/profile 
[root@localhost mysql]# cd ~
#这样我们在任意目录都可以连接进入数据库了
#目前数据库root密码依然为空  可直接进行连接
[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# 
#连接成功,接下来我们修改root密码
[root@localhost ~]# mysqladmin -u root password '123456'
Warning: Using a password on the command line interface can be insecure.
[root@localhost ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#说明密码已经生效
#咱们加上密码再次连接
[root@localhost ~]# mysql -u root -p123456
....
#成功, 当然 你也可以在上面测试连接成功的时候直接通过数据库操作更新密码
#过程如下:
mysql> use mysql;
mysql> select user,host from user;
mysql> delete from user where user='';
mysql> update user set password=password('123456') where user='root';
mysql> flush privileges;
mysql> quit
#这时你也可以用
[root@localhost ~]# mysql -u root -p
#然后手动输入密码进行登录 (这样可以避免其他人通过查看 bash history知道了密码)
好的,到这里

mysql 的安装与测试连接就告一段落了

如果你希望每次开机时mysqld 服务自动启动,可以执行如下命令

[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig mysqld --list
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭


ok 这样就不用担心以后重启电脑 忘了启动 mysqld服务了




运维 CentOS MySql

(0) (1280)

发表评论: