Linux服务器---安装mysql

安装mysql

1 、检测是否已安装mysql

[root@localhost bin]#  rpm -qa | grep mysql

mysql-libs-5.1.71-1.el6.i686

[root@localhost bin]

 

2 、安装mysql和mysql-server 

[root@localhost bin]#  yum install -y mysql

[root@localhost bin]#  yum install -y mysql-server

 

3 、启动mysql,注意这里的服务名字是“mysqld”

[root@localhost bin]#  service mysqld start

shell-init: error retrieving current directory: getcwd: cannot access parent directories:  没有那个文件或目录

chdir: error retrieving current directory: getcwd: cannot access parent directories:  没有那个文件或目录

初始化  MySQL  数据库:  Installing MySQL system tables...

OK

Filling help tables...

OK                                                         [ 确定 ]

正在启动  mysqld                                           [ 确定 ]

[root@localhost bin]# 

 

4 、配置MySQL开机启动 

[root@localhost bin]#  chkconfig mysqld on

[root@localhost bin]#  chkconfig --list mysqld

mysqld         0: 关闭   1: 关闭   2: 启用   3: 启用   4: 启用   5: 启用   6: 关闭

[root@localhost bin]# 

 

5 、设置root用户密码 ,设置密码的命令是“ mysqladmin -u  用户名 password 密码

[root@localhost bin]#  mysqladmin -u root password 543092   // 密码是 543092

 

6 、修改密码,命令是“ mysqladmin -u  用户名 -p password  新密码 ” 

[root@localhost bin]#  mysqladmin -u root -p password 123456     // 新密码 123456

Enter password:        // 这里要求输入旧密码

[root@localhost bin]# 

 

7 、mysql配置文件“/etc/my.cnf” 

[root@localhost bin]#  cat /etc/my.cnf 

[mysqld]

datadir=/var/lib/mysql            // 数据库文件目录

socket=/var/lib/mysql/mysql.sock    //socket 文件

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log     // 日志文件

pid-file=/var/run/mysqld/mysqld.pid    // 进程 pid 文件

 

 

8 、修改端口

1 )mysql默认的端口是3306,可以使用netstat来查看

[root@localhost bin]#  netstat -tunlp | grep mysqld

tcp        0      0 0.0.0.0:3306               0.0.0.0:*                  LISTEN      4339/mysqld         

2 )端口在配置文件中修改,打开配置文件,在后面追加一句话”port=xxx” 

[root@localhost bin]#  gedit /etc/my.cnf

port=3307      

3 )重启myslqd服务,查看端口 

[root@localhost bin]#  service mysqld restart

shell-init: error retrieving current directory: getcwd: cannot access parent directories:  没有那个文件或目录

chdir: error retrieving current directory: getcwd: cannot access parent directories:  没有那个文件或目录

^[[A 停止 mysqld                                           [ 确定 ]

正在启动 mysqld                                           [ 确定 ]

[root@localhost bin]# netstat -tunlp | grep mysqld

tcp        0      0 0.0.0.0:3307               0.0.0.0:*                   LISTEN      4604/mysqld              

 



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29270124/viewspace-2221719/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29270124/viewspace-2221719/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值