您的位置:首页 > 运维架构 > Linux

MySQL安装与应用【Linux下的安装与配置】

2012-03-09 00:00 190 查看

Linux下的安装与配置

如果所安装的Linux系统没有内置的MySQL,笔者建议在Linux中使用RPM包来安装MySQL,同样这也是MySQL官方提供的建议。笔者接触最多的Linux系统是Radhat的“近亲”:CentOS,由于CentOS较新的版本都内置了MySQL,因此在安装系统时就将MySQL安装并注册为系统服务,省去了不少工作量,此处也就不对Linux下的安装做太多陈述,仅提供部分资料供参考。

注意: MySQL至少需要Linux 2.0版本。

以下是网友提供的CentOS 5下安装MySQL的步骤(出处:http://wenda.tianya.cn/wenda/thread?tid=0c194eed74f2577b),仅供参考。

CentOS5下MySQL的安装步骤

创建mysql用户组和用户

[root@centos ]# groupadd mysql

[root@centos ]# useradd -g mysql mysql

[root@centos ]# cd homexule

[root@centos ]# chmod 755 mysql-5.0.22.tar.gz

编译并安装MySQL

[root@centos ]# tar zxvf mysql-5.0.22.tar.gz

[root@centos ]#cd mysql-5.0.22

[root@centos mysql-5.0.22] .configure --prefix=usrlocalmysql

[root@centos mysql-5.0.22] make

[root@centos mysql-5.0.22] make install

配置并启动MySQL

[root@centos mysql-5.0.22]# cp support-filesmy-medium.cnf etcmy.cnf

[root@centos mysql-5.0.22]# cd usrlocalmysql

[root@centos mysql]# binmysql_install_db --user=mysql

Installing all prepared tables

Fill help tables

To start mysqld at boot time you have to copy support-filesmysql.server

to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands

usrlocalmysqlbinmysqladmin -u root password 'new-password'

usrlocalmysqlbinmysqladmin -u root -h centos.job100.com password 'new-password'

See the manual for more instructions.

You can start the MySQL daemon with

cd usrlocalmysql ; usrlocalmysqlbinmysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory

cd sql-bench ; perl run-all-tests

Please report any problems with the usrlocalmysqlbinmysqlbug script!

The latest information about MySQL is available on the web at

httpwww.mysql.com

Support MySQL by buying supportlicenses at httpshop.mysql.com

[root@centos mysql]# binmysqld_safe --user=mysql &

[1] 20100

[root@centos mysql]# Starting mysqld daemon with databases from usrlocalmysqlvar

添加管理性用户 要管理MySQL 需要创建一个管理性账户

[root@centos mysql]# binmysqladmin -u root password job100

红色标注密码

让MySQL自动启动

进入安装目录

[root@centos mysql]# cd homexulemysql-5.0.22

[root@centos mysql-5.0.22]# cp support-filesmysql.server etcrc.dinit.dmysql

[root@centos mysql-5.0.22]# chmod +x etcrc.dinit.dmysql

[root@centos mysql-5.0.22]# chkconfig --level 3 --add mysql

查看MYSQL运行状态

[root@centos bin]# usrlocalmysqlbinmysqladmin -u root -p version proc

Enter password

usrlocalmysqlbinmysqladmin Ver 8.41 Distrib 5.0.22, for pc-linux-gnu on i686

Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL license

Server version 5.0.22-log

Protocol version 10

Connection Localhost via UNIX socket

UNIX socket tmpmysql.sock

Uptime 33 min 3 sec

Threads 1 Questions 5 Slow queries 0 Opens 0 Flush tables 1 Open tables 6 Queries per second avg 0.003

+----+------+-----------+----+---------+------+-------+------------------+

Id User Host db Command Time State Info

+----+------+-----------+----+---------+------+-------+------------------+

2 root localhost Query 0 show processlist

+----+------+-----------+----+---------+------+-------+------------------+

关于Linux下安装MySQL的详细步骤,请参考MySQL官方的在Linux下安装MySQL ,文中详细介绍了不同Linux版本下如何使用合适的RPM包安装MySQL的方法。

使用MySQL AB's Linux RPM分发进行安装后,将在以下系统目录产生文件:

目录
目录内容
/usr/bin
客户端程序和脚本
/usr/sbin
mysqld服务器
/var/lib/mysql
日志文件,数据库
/usr/share/doc/packages
文档
/usr/include/mysql
包含(头)文件
/usr/lib/mysql

/usr/share/mysql
错误消息和字符集文件
/usr/share/sql-bench
基准程序
下面以CentOS自带的MySQL为例说明如何启动并验证MySQL服务是否正常,以及常用的MySQL各种配置。

1. 执行shell>mysql,若提示"can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock'",

说明mysql服务还没有启动,请运行/etc/init.d/mysqld start,成功后会提示启动成功!

2. 更改字符集编码为UTF-8

找到my.cnf,利用文本编辑器打开,在[mysqld]下面加入以下2行

default-character-set=utf8

init_connect='SET NAMES utf8'

再增加以下内容,在此文件的最后

[client]

default-character-set=utf8

保存后,重启mysql服务。可通过服务管理进行。

验证编码

运行mysql,

mysql> show variables like 'character%';

显示结果为以下内容为正确

+--------------------------+----------------------------+

| Variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

3. 给与远程登录数据库的权限

进入mysql,执行以下语句

mysql>grant all on *.* to 'root'@'%';

连接数据库

1. 在终端中录入:“mysql”,完成连接数据库的操作

2. “show databases;”命令,显示当前所有的数据库

3. 如果目标数据库不存在,运行“create database db_name;”命令,完成创建数据库操作(其中,“db_name”为目标数据库名称)

4. “use db_name;”命令,完成获取当前数据库,其中,“db_name”为需要连接的数据库名

5. “show tables;”命令,查看数据库中是否有表

6. “exit”退出mysql

7. 终端中录入“mysql db_name < db_name.sql -u root”完成对mysql文件的导入工作(其中,“db_name”为需要导入的数据库名;“<”号是必须的)

更改MySQL 的root 用户密码

1. 在终端中录入“mysqladmin -uroot -p password root”

2. 为确认密码更改成功,再次录入“mysqladmin -uroot -proot password root”

更改MySQL 区分大小写的设置

1. linux下MySQL对数据库名及表名是区分大小写的,会造成table找不到的现象

2. 打开/etc/my.cnf文件,在“[mysqld]”下一行,添加“lower_case_table_names=1”,更改默认不区分大小写

3. 保存文件

4. 重新启动mysql,OK

$(document).ready(function(){dp.SyntaxHighlighter.HighlightAll('code');});

原文链接:
http://blog.csdn.net/cyq1984/article/details/5024727
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: