欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Linux服务器---安装mysql

程序员文章站 2023-09-29 11:16:55
安装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@local ......

安装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