爱程序网

mysql for linux 数据库的安装过程

来源: 阅读:

mysql for linux 数据库的安装过程

l  安装版本:mysql-advanced-5.6.12-linux-glibc2.5-x86_64.tar.gz ,此版本是绿色版本,只需要将其解压到相关目录即可。

PS:此安装方法为不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件

 PS:Mysql下载地址:http://pan.baidu.com/s/1eQJhoLO

 

1、创建mysql用户/账号

[root@inmscj10 ~]#  groupadd mysql         --增加组

[root@inmscj10 ~]#  useradd -m -s/bin/bash -d/home/mysql -gmysql mysql   --增加用户并指定用户位置,路径,用户组

[root@inmscj10 ~]#  passwd mysql    --修改密码

[root@inmscj10 ~]#  

 

2、创建目录

l  为了好管理,将mysql统一安装在一个固定的目录/home/下,将解压后的mysql重命名为mysql

[root@inmscj10 ~]# mkdir -p /home/

[root@inmscj10 ~]# tar -zxvf mysql-advanced-5.6.12-linux-glibc2.5-x86_64.tar.gz

[root@inmscj10 ~]# mv mysql-advanced-5.6.12-linux-glibc2.5-x86_64 /home/mysql

l  在主目录下面创建一个logs目录,用户存放mysql的日志文件。

[root@inmscj10 mysql]# mkdir logs

l  对相关目录进行授权

[root@inmscj10 ~]#cd /home/mysql/

[root@inmscj10 mysql]#chown -R root 

[root@inmscj10 mysql]#chown -R mysql data

[root@inmscj10 mysql]#chgrp -R mysql 

 

3、初始化数据库

mysql的原始配置文件可以在support-files中找到

my-default.cnf,这个是mysql的参数文件,通常这个文件都会被重新命名为my.cnf,放入/home/mysql目录下。

[root@inmscj10 support-files]# cp my-default.cnf -C /home/mysql/my.cnf

l  修改my.cnf文件,加入以下内容:

[mysqld]
basedir = /home/mysql     --安装根目录
datadir = /home/mysql/data    --数据库存储路径
socket = /tmp/mysql.sock
log-error=/home/mysql/mysql_error.log
skip-name-resolve
character_set_server=utf8
#init_connect='set names utf8'

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

max_allowed_packet = 32M
table_open_cache = 1024
sort_buffer_size = 4M
join_buffer_size = 2M
net_buffer_length = 8M
read_buffer_size = 4M
read_rnd_buffer_size = 8M
thread_cache_size = 300
query_cache_size = 1024M
query_cache_limit = 2M
thread_concurrency = 8
wait_timeout = 315360000
max_connections = 300
max_connect_errors=1844674407370954751
max_connect_errors = 10000
#event_scheduler=1

#innodb_log_file_size=256M
innodb_buffer_pool_size = 4094M  
innodb_additional_mem_pool_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_thread_concurrency=8
#innodb_sort_buffer_size=32M
innodb_open_files=4096
innodb_write_io_threads=2
innodb_read_io_threads=2
innodb_max_dirty_pages_pct = 90
innodb_file_per_table=1

[client]
socket=/tmp/mysql.sock
default-character-set=utf8

 

l  进入script目录

[root@inmscj10 mysql]# cd scripts/

[root@inmscj10 scripts]#./mysql_install_db --defaults-file=/home/mysql/my.cnf--datadir=/home/mysql/data --basedir=/home/mysql

 

注:这个地方一定要指定数据库文件存放的路径,否则后面启动过程中会报错。

 

4、配置文件的修改、

l  修改环境配置,在.bash_profile 修改添加


PATH=$PATH:$HOME/bin:/home/mysql/bin

export PATH=$PATH:/home/mysql/bin

 

l  在 /etc/security/limits.conf 添加下列行,修改账号资源限制(如无需要可不配)

mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65536
mysql hard nofile 65536

l  修改后重启脚本与查看修改情况

[mysql@gdcs1 java]$  source /etc/security/limits.conf

[mysql@gdcs1 java]$   ulimit -a

open files                      (-n) 65536

max user processes              (-u) 65536

 

PS:如需具体了解linux ulimit请参考:http://blog.csdn.net/wanghai__/article/details/6332540

 

l  mysql.server,这个文件是mysql的服务文件,通常这个文件被重新命名为mysql或mysqld,放入/etc/rc.d/init.d/目录下面

[root@inmscj10 support-files]# cpmysql.server  /etc/rc.d/init.d/mysqld

编辑该文件,修改对于的目录为正确的目录,如下

basedir=/home/mysql

datadir=/home/mysql/data

这样设置以后就可以用service  mysqld start/stop来启动关闭mysql服务。

 

遗留问题:由于修改了配置文件的路径和文件名,但在服务文件mysqld中指定的配置文件路径仍然是/etc/my.cnf,所以,在启动和关闭mysql数据用service mysqld start/stop会有问题(不能读到正确的参数文件)

 

5、数据库服务启动

进入mysql的主目录:

[root@inmscj10mysql]#.bin/mysqld_safe --defaults-file=/home/mysql/my.cnf --user=mysql&     --初始化数据库

 

启动服务后,通过ps命令可以查看数据库的目录结构情况:

[root@inmscj10 mysql01]# ps -ef | grep mysql

 

6、数据库用户配置

1)root用户设置密码

[root@inmscj10 ~]# mysqladmin -u rootpassword 'mysql' 

2)数据登录

[root@inmscj10 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 4

Server version: 5.1.48-community MySQLCommunity Server (GPL)

Copyright (c) 2000, 2010, Oracle and/orits affiliates. All rights reserved.

This software comes with ABSOLUTELY NOWARRANTY. This is free software,

and you are welcome to modify andredistribute it under the GPL v2 license

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

mysql>

3)给root用户配置远程访问权限,设置后可通过客户连接。

mysql> GRANT ALL PRIVILEGES on *.* to'root'@'%' identified by 'illusioned'; 

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

4)增加一个develop的新用户并赋予所有权限

mysql> GRANT ALL PRIVILEGES ON *.* TOdevelop@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;

给新用户远程登录操作权限

mysql> GRANT ALL PRIVILEGES on *.*to 'develop'@'%' identifiedby '123456';(赋予远程操作权限)

给新用户本地登录操作权限

mysql> GRANT ALL PRIVILEGES on *.*to 'develop'@'localhost' identifiedby '123456'; (赋予本地操作权限)

 

7、参数的设置与修改

mysql的的参数修改与设置有两种方法,一是通过修改参数文件(master.cnf)完成,参数文件有时候不完全,不存在的参数需要手工增加,但是修改参数文件的可能需要重启数据库才能生效;二是通过set命令来完成,这种情况不需要重启。

通过show VARIABLESLIKE '....'来查看参数情况,如下:

mysql> show VARIABLES LIKE'character%';

 

部分参数查看及设置如下:

1)开启事件调度

set global event_scheduler =1;

2)查看是否支持分区

show variables like '%partition%';

有的版本无法用此参数查看分区,则用下面语句。

show plugins;

确认partition是否为active状态

| partition                 | ACTIVE   | STORAGE ENGINE     |NULL    | PROPRIETARY |
3)查看调度任务创建情况

show events;

4)查看字符集

show variables like '%character%';

临时改变字符集

set names utf8

5)查看MYSQL打开文件数限制

show variables like 'open%';

show global status like 'open_%';

 

8、问题

问题一:

[ERROR] Fatal error: Can't open and lock privilegetables: Table 'mysql.user' doesn't exist

FATAL ERROR: Could not find ./bin/my_print_defaults

问题原因:在初始化数据库的时候使用了默认路径安装数据库,但实际上配置文件已经修改了相关的数据库文件路径。

解决方法:如果改变了数据文件存放的目录,务必指定datadir位置

[root@inmscj10 scripts]# ./mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data &

 

问题二:

ERROR 2002 (HY000): Can't connect to local MySQL serverthrough socket '/var/lib/mysql/mysql.sock' (111)

问题原因:一些mysql安装将mysql.sock放在了/var/lib/mysql没有了下面,一些mysql放在了/tmp下面。由于以前机器上面已经安装了一个mysql客户端,mysql.sock位置不一样。

解决方法:在参数文件my.cnf中指定mysql.sock参数的路径。

[mysqld]
socket=/var/lib/mysql.sock

 

问题三:

error: 'Access denied for user 'root'@'localhost' (usingpassword: NO)'

问题原因:可能的原因是安装了数据库后,没有设置root密码;或者某些操作不当造成的。

解决方法:执行如下语句。

利用kill语句先停掉数据库服务,执行,

[root@inmscj10 mysql01]#.bin/mysqld_safe./bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

[root@inmscj10 mysql01]#.mysql -u root

mysql> use mysql

mysql> update user set password=PASSWORD(cattsoft)where user='root'

mysql> flush privileges;

mysql> quit;

重启数据库服务

 

问题四:

[ERROR]Plugin 'InnoDB' init function returned error.

问题原因:由于数据库初始化过程中少加了参数等一系列其他原因造成。

解决方法:删除MySQL目录下的ib_logfile0和ib_logfile1两个文件即可。

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助