Linux系统自带的MySQL 数据库启动问题


针对Linux系统自带Mysql 数据库不能使用的情况,可能是在安装过程有没有安装mysql server 安装时即使选了安装MYSQL(图形界面安装),只有打开旁边“细节”,从里面勾选选上server才可以。

安装完成后在/usr/bin 目录下会生成许多MySQL的相关文件,其中有一个名为mysqld_safe 启动服务的脚本文件,执行这个脚本文件后,发现错误'/var/lib/mysql/mysql.sock' 查看mysql服务才发现,没有起来,于是执行/etc/init.d/mysqld start启动服务后,/usr/bin 执行mysql 成功进入数据库!

[pan@localhost ~]$ su – root

Password:

[root@localhost ~]# cd /usr/bin

[root@localhost bin]# ./mysqld_safe --user=root &

[1] 12969

[root@localhost bin]# Starting mysqld daemon with databases from /var/lib/mysql

STOPPING server from pid file /var/run/mysqld/mysqld.pid

090606 15:20:04 mysqld ended

mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[1]+ Done                    ./mysqld_safe --user=root

[root@localhost bin]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[root@localhost bin]# /etc/rc.d/init.d/mysqld status

mysqld is stopped

[root@localhost bin]# /etc/init.d/mysqld start (或者service mysqld restart,而service mysqld stop 停止mysql的服务)

Initializing MySQL database:                               [ OK ]

Starting MySQL:                                            [ OK ]

[root@localhost bin]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2 to server version: 4.1.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

现在进行环境变量的配置,可以针对用户配置用户的环境变量,以root用户例,

[root@localhost bin]# cd

[root@localhost ~]# ls –a .bash_profile 是个隐藏文件,所以要-a

. Desktop          .gstreamer-0.8      .mozilla

..               .dmrc            .gtkrc              .mysql_history

anaconda-ks.cfg .eggcups         .gtkrc-1.2-gnome2   .nautilus

.bash_history    .fullcircle      .ICEauthority       .recently-used

.bash_logout     .gconf           .icons              .rhn-applet.conf

.bash_profile    .gconfd          install.log         .tcshrc

.bashrc          .gnome           install.log.syslog .viminfo

.config          .gnome2          .kde                .xauthC1s54N

.cshrc           .gnome2_private .metacity           .xautheKBniS

[root@localhost ~]# vi .bash_profile (进行修改)

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/bin (此处添加注意冒号)

export PATH

unset USERNAME

[root@localhost ~]# source .bash_profile (更新一下配置文件)

也可以针对系统环境配置,如下:

[root@localhost ~]# vi /etc/profile

# /etc/profile

# System wide environment and startup programs, for login setup

# Functions and aliases go in /etc/bashrc

pathmunge () {

        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then

           if [ "$2" = "after" ] ; then

             PATH=$PATH:$1

           else

              PATH=$1:$PATH

           fi

        fi

}

# Path manipulation

if [ `id -u` = 0 ]; then

        pathmunge /sbin

        pathmunge /usr/sbin

        pathmunge /usr/local/sbin

        pathmunge /usr/bin

fi

相关内容