一、Root用户操作
1、创建普通用户
1
2
|
[root@localhost ~]
# useradd ipdev
[root@localhost ~]
# echo "ipdev" |passwd --stdin ipdev > /dev/null
|
2、创建运行mysql服务的用户
1
|
[root@localhost ~]
# useradd mysql
|
3、验证用户是否创建成功
1
2
3
4
|
[root@localhost ~]
# id ipdev
uid=500(ipdev) gid=500(ipdev) 组=500(ipdev)
[root@localhost ~]
# id mysql
uid=501(mysql) gid=501(mysql) 组=501(mysql)
|
4、赋予普通用户ipdev执行sudo的权限
1
2
|
[root@localhost ~]
# echo "ipdev ALL=(ALL:ALL) ALL" > /etc/sudoers.d/ipdev
[root@localhost ~]
# chmod 400 /etc/sudoers.d/ipdev
|
5、首次初始化数据库时的依赖包先安装之
1
|
[root@localhost ~]
# yum -y install libaio
|
二、Indev用户操作 | 普通用户
1、准备工作
1
2
3
4
5
6
7
8
|
[ipdev@localhost ~]$
who
root tty1 2014-12-04 23:24
root pts
/0
2014-12-04 23:25 (192.168.0.103)
ipdev pts
/1
2014-12-04 23:31 (192.168.0.103)
[ipdev@localhost ~]$
pwd
/home/ipdev
[ipdev@localhost ~]$
ls
mysql-5.6.12-linux-glibc2.5-x86_64.
tar
.gz
|
2、解压Mysql安装包
1
2
3
4
5
6
7
|
[ipdev@localhost ~]$
tar
xf mysql-5.6.12-linux-glibc2.5-x86_64.
tar
.gz
[ipdev@localhost ~]$
ln
-s mysql-5.6.12-linux-glibc2.5-x86_64 mysql
[ipdev@localhost ~]$ ll
总用量 299028
lrwxrwxrwx 1 ipdev ipdev 34 12月 4 23:35 mysql -> mysql-5.6.12-linux-glibc2.5-x86_64
drwxrwxr-x 13 ipdev ipdev 4096 12月 4 23:35 mysql-5.6.12-linux-glibc2.5-x86_64
-rw-rw-r-- 1 ipdev ipdev 306192671 12月 4 23:33 mysql-5.6.12-linux-glibc2.5-x86_64.
tar
.gz
|
3、创建数据存储目录
1
|
[ipdev@localhost ~]$
mkdir
data
|
4、赋予Mysql安装程序目录和数据存放目录权限
#重点标记:数据存放目录data的权限一定要控制好,否则后续初始化数据库的时候就会报错
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[ipdev@localhost ~]$
chown
-R mysql data
chown
: 正在更改
"data/"
的所有者: 不允许的操作
[ipdev@localhost ~]$
sudo
chown
-R mysql data
We trust you have received the usual lecture from the
local
System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[
sudo
] password
for
ipdev:
[ipdev@localhost ~]$
sudo
chown
-R mysql mysql
[ipdev@localhost ~]$ ll
总用量 299032
drwxrwxr-x 2 mysql mysql 4096 12月 4 23:35 data
lrwxrwxrwx 1 mysql ipdev 34 12月 4 23:35 mysql -> mysql-5.6.12-linux-glibc2.5-x86_64
drwxrwxr-x 13 mysql ipdev 4096 12月 4 23:35 mysql-5.6.12-linux-glibc2.5-x86_64
-rw-rw-r-- 1 ipdev ipdev 306192671 12月 4 23:33 mysql-5.6.12-linux-glibc2.5-x86_64.
tar
.gz
|
5、初始化数据库
1
|
[ipdev@localhost ~]$ .
/mysql/scripts/mysql_install_db
--user=mysql --datadir=
/home/ipdev/data/
--basedir=
/home/ipdev/mysql/
|
在初始化数据库的时候,我遇到两个错误如下
1
2
3
4
5
6
|
***********************************遇到的错误***********************************************************
Installing MySQL system tables...2014-12-04 23:37:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation
for
more
details).
2014-12-04 23:37:26 1438 [Warning] Can't create
test
file
/home/ipdev/data/localhost
.lower-
test
错误1
2014-12-04 23:37:26 1438 [Warning] Can't create
test
file
/home/ipdev/data/localhost
.lower-
test
2014-12-04 23:37:26 1438 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000) 错误2
*********************************************************************************************************
|
解决办法
1
2
3
4
5
6
7
8
9
10
11
|
错误1的解决办法:
sudo
chown
-R mysql.mysql data
而非
sudo
chown
-R mysql.mysql data
错误2的解决办法
# sudo vim /etc/security/limits.conf
末尾行增加如下信息
* soft nofile 65535
* hard nofile 65535
普通用户需要重新登录,才能生效,查看命令umilit -n
|
6、修改补充Mysql配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
$ vim ~
/mysql/my
.cnf
[mysqld]
添加如下行
user = mysql
port = 3306
server_id = 1
socket =
/tmp/mysql
.sock
basedir =
/home/ipdev/mysql/
datadir =
/home/ipdev/data/
log-error =
/home/ipdev/data/mysql-error
.log
pid-
file
=
/home/ipdev/data/mysql
.pid
log-bin =
/home/ipdev/data/mysql-bin
.log
open
-files-limit = 10240
skip_name_resolve=1
innodb_file_per_table=1
|
7、启动Mysql服务
注意:启动的时候也很重要,否则也会报很多错误
1
2
|
[ipdev@localhost ~]$
sudo
sed
-i
's#/usr/local#/home/ipdev#g'
~
/mysql/bin/mysqld_safe
[ipdev@localhost ~]$ ~
/mysql/bin/mysqld_safe
--defaults-
file
=
/home/ipdev/mysql/my
.cnf &
|
8、配置Mysql环境变量
1
2
|
[ipdev@localhost ~]$
echo
"export PATH=\$PATH:/home/ipdev/mysql/bin/"
>> ~/.bash_profile
[ipdev@localhost ~]$
source
~/.bash_profile
|
9、登陆测试
1
2
3
4
5
6
7
8
9
10
|
[ipdev@localhost ~]$ mysql -uroot -p -e
'show databases;'
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
|
test
|
+--------------------+
|
10、由于时间比较仓促,这里就不在多修改服务启动脚本了
1
|
killall -9 mysqlpid | or |
kill
mysqlpid
|
需要注意几个地方:
1、目录权限问题 (比如数据存放目录,各种日志目录)
2、执行权限问题 (如sudo)
3、启动服务时建议指明配置文件的路径
4、最大的一个问题就是初始化数据库 默认./bin/mysqld_safe的Mysql路径为/usr/local/mysql,但是普通用户对/usr/local是没有访问权限的,因此这个地方一定要替换成Mysql的目录
本以为很简单,但是做起来真的很麻烦
好了,今天就先到这里!后续还会继续补充 大家 晚安
本文转自zys467754239 51CTO博客,原文链接:http://blog.51cto.com/467754239/1586491,如需转载请自行联系原作者