【linux】安装mysql

将mysql安装文件(下载地址:http://www.mysql.com/downloads/mysql-4.0.html

MySQL-client-community-5.0.37-0.rhel3.i386.rpm

MySQL-server-community-5.0.37-0.rhel3.i386.rpm

perl-DBI-1.53-2.fc7.i386.rpm

ftp上传到安装目录。用数据库用户登录系统,进行mysql的安装。

 

以下需要root权限:

查询是否安装过mysql

[root@宁波测试机 ~]$ rpm -qa|grep mysql

如果已经安装,需要卸载:

rpm -e MySQL-client-community MySQL-server-community

 

以下需要数据库用户权限:

[dbuser@宁波测试机 ~]$ rpm -ivh  MySQL-server-community-5.0.37-0.rhel3.i386.rpm

如果出现如下信息:
error: Failed dependencies:
        perl(DBI) is needed by MySQL-server-community-5.0.37-0.rhel3.i386


则需要执行:

[dbuser@宁波测试机 ~]$ rpm -ivh  perl-DBI-1.53-2.fc7.i386.rpm
error: can't create transaction lock on /var/lib/rpm/__db.000
说明权限不够,需要su到root用户,执行:

[root@宁波测试机 db]# rpm -ivh   perl-DBI-1.53-2.fc7.i386.rpm
Preparing...                ########################################### [100%]
   1:perl-DBI               ########################################### [100%]

 

执行安装

[root@宁波测试机 db]# rpm -ivh  MySQL-server-community-5.0.37-0.rhel3.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 宁波测试机 password 'new-password'
See the manual for more instructions.

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

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Starting MySQL[确定]

[root@宁波测试机 db]# rpm -ivh  MySQL-client-community-5.0.37-0.rhel3.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client-community ########################################### [100%]

 

安装完后,需要对mysql进行配置

见“mysql问题总结”中的my.cnf配置

 

注:my.cnf文件的获取:

如果你的内存≤64M,则复制/usr/share/mysql/my-small.cnf为/etc/my.cnf
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.

如果内存是128M,则复制/usr/share/mysql/my-medium.cnf为/etc/my.cnf
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)

如果内存是512M,则复制/usr/share/mysql/my-large.cnf为/etc/my.cnf
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.

如果内存是1-2G,则复制/usr/share/mysql/my-huge.cnf为/etc/my.cnf
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.

如果内存是4G,则复制/usr/share/mysql/my-innodb-heavy-4G.cnf为/etc/my.cnf
# This is a MySQL example config file for systems with 4GB of memory
# running mostly MySQL using InnoDB only tables and performing complex
# queries with few connections.

 

数据库启动命令权限分配

数据库启动命令现在只有root用户可以执行,我们想把权限分配给dbuser用户,给root分权,可以这样做:

      更改sudo配置文件/etc/sudoers,增加如下内容:

          Cmnd_Alias MYSQL=/etc/init.d/mysql, /usr/bin/mysqld_safe, /usr/bin/mysqladmin

          dbuser  ALL=(ALL) NOPASSWD:MYSQL

      之后就可以通过dbuser用户启动、停止mysql,命令如下:

 

启动:sudo /etc/init.d/mysql start
停止:sudo /etc/init.d/mysql stop

 

 

给root用户设置密码

刚安装好的mysql,root用户可以不用密码,直接登陆数据库,需要将root设置密码来降低风险。在mysql命令行输入:

set password for root@localhost =PASSWORD('newPassword');

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值