Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208171
  • 博文数量: 53
  • 博客积分: 2059
  • 博客等级: 大尉
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 03:03
文章分类
文章存档

2012年(4)

2011年(19)

2010年(30)

分类: Mysql/postgreSQL

2010-07-08 03:19:38

1.下载Mysql需要的安装包,一下两个文件
MySQL-client-community-5.1.48-1.rhel5.i386.rpm
MySQL-server-community-5.1.48-1.rhel5.i386.rpm
下载地址为:
在下载页面上选择你系统所需要的RPM包
2.安装Mysql,安装Mysql分为两个部分,一是安装服务器端,二是安装客户端,其实我们为了便于管理和易用性往往在服务器上既安装server也安装client软件。
2.1安装服务器端
rpm -ivh MySQL-server-community-5.1.48-1.rhel5.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server-community ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h test-1.skymobi.com password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

Starting MySQL.[  OK  ]
Giving mysqld 2 seconds to start
至此安装完成,可以发现Mysql安装完成切已经启动。如果出现包依赖关系,请按照提示安装相应的依赖包。
2.2安装服务器端
 rpm -ivh MySQL-client-community-5.1.48-1.rhel5.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client-community ########################################### [100%]
由于Mysql 运行的监听端口为TCP 3306 我们可以通过查看端口来,测试Mysql是否启动
netstat -an |grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
以上信息证明Mysql已经启动。
登陆测试,初次安装登陆Mysql Mysql默认root用户密码为空
 mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.48-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>
3.Mysql相关设置
1,密码和登陆设置
我们可以用命令 mysql_secure_installation进行相关的设置
 mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
这里我已经通过命令mysqladmin 更改过默认密码 语法为:
mysqladmin  -uroot password 'newpassword'
这里我们键入新密码
[root@test-1 ~]# mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

以上我们可以根据提示来一步一步操作,再次不做说明
3.2,MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/data下需要进行下面几步:
1.、home目录下建立data目录
cd /home
mkdir data
2、把MySQL服务进程停掉:
mysqladmin -u root -p shutdown
3、把/var/lib/mysql整个目录移到 /home/data
mv /var/lib/mysql /home/data/
这样就把MySQL的数据文件移动到了/home/data/mysql下
4、找到 my.cnf配置文件
如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/ 下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf)中。命令如下:
[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
说明在/usr/share/mysql/下面有四个不同模式mysql运行配置文件:
my-large.cnf
my-medium.cnf
my-small.cnf
my-huge.cnf
5、编辑MySQL的配置文件/etc/my.cnf
为保证MySQL能够正常工作,需要指明mysql.sock文件的产生位置。 修改socket=/var/lib/mysql/mysql.sock 一行中等号右边的值
为:/home/mysql/mysql.sock 。操作如下:
vi  my.cnf ##用vi工具编辑my.cnf文件,找到下列数据修改之
# The MySQL server
[mysqld]
port  = 3306
#socket = /var/lib/mysql/mysql.sock ##原内容,为了更稳妥用“#”注释此行
socket = /home/data/mysql/mysql.sock  #加上此行
3.3为了在其它电脑上能用root用户登录,需进行以下动作:
1、mark@marklinux mark>mysql -h localhost -u root
//这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
//赋予任何主机访问数据的权限
例子:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.27.79' identified  by 'skymobi' WITH GRANT OPTION;
连接成功





3.4相关说明:
3.4.1 Mysql默认安装路径
find / -name mysql
/usr/bin/mysql        #mysql 运行命令目录
/usr/lib/mysql         #mysql运行相关lib库
/usr/share/doc/openldap-servers-sql-2.3.43/rdbms_depend/mysql  #mysql相关文档
/usr/share/mysql  #是目录下面有相关Mysql文档
/var/lib/mysql  #Mysql相关数据库存放目录
/var/lib/mysql/mysql
/var/lock/subsys/mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql #mysql启动脚本
3.4.2启动与停止加入自启动
/etc/init.d/mysql start|restart|stop|status

chkconfig --list |grep mysql  查看mysql是不是自启动
chkconfig --level 35 mysql on    添加运行界别35 自启动
阅读(3215) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~