您的位置:首页 > 运维架构 > Linux

centos下使用mysql的一些问题和解决方法

2017-04-16 17:17 585 查看
【问题1】在centos6.8上使用yum直接安装MySQL,一切正常安装。启动mysql时显示: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)(1)、cp /usr/share/mysql/my-medium.cnf/ /etc/my.cnf(将默认的配置文件模板复制过去覆盖原有的配置文件);(2)、/etc/init.d/mysqld status查看MySQL运行状态,显示正常;(3)、解决办法:vim /etc/my.conf ,在[mysqld]下面加入一句话:
【现在直接输入mysql直接进入mysql命令窗口】

【问题2】不能用mysql -u root -p 登录,显示:
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)解决办法: 在mysql配置文件/etc/my.conf中的[mysqld]中加入:
pid-file=/var/lib/mysql/mysqlid.pid
原因:mysql 用户没有操作/var/run目录的权限,所以pid文件无法创建,导致登陆时无法建立 进程信息文件,登陆进程就无法开启,自然无法登陆。

【问题3】刚刚装好的mysql没有为root设置密码,直接输入mysql就可以登录,为root设置密码的方法:
在linux命令行界面输入:
mys1qladmin -u root password '123'
再次用root身份登录:
mys1ql -uroot -p

【问题4】之前装好一个mysql,但是由于忘记了root密码,于是把文件/application/mysql删除了,然后重新解压一个mysql文件到/application下,并按照步骤设好各种环境,但是打开mysql是还是会有问题,显示:
[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL...The server quit without updating PID file [失败] ication/ mysql/ data/localhost. localdomain.pid).
查看有关mysql的进程
[root@localhost support-files]# ps -ef | grep mysql
root 12821 1 0 May15 ? 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/localhost.localdomain.pid
mysql 12949 12821 0 May15 ? 00:00:14 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/localhost.localdomain.err --pid-file=/application/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock
root 18450 17925 0 10:10 pts/0 00:00:00 grep mysql
杀死这两个进程
[root@localhost support-files]# kill -9 12821
[root@localhost support-files]# kill -9 12949
再次打开mysql
[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL.. [确定]
[root@localhost support-files]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> quit
Bye

【问题5】初始化数据库报错如下,执行
/application/mysql-5.6.36/scripts/mysql_install_db --datadir=/application/mysql-5.6.36/data/ --basedir=/application/mysql-5.6.36/ --user=mysql 时报以下错误:
-bash: /application/mysql-5.6.36/scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
【解决办法】
yum -y install perl perl-devel

【问题6】在问题5的基础上,安装好了perl,再次执行初始化数据库命令
/application/mysql-5.6.36/scripts/mysql_install_db --datadir=/application/mysql-5.6.36/data/ --basedir=/application/mysql-5.6.36/ --user=mysql 时报以下错误:
FATAL ERROR: please install the following Perl modules before executing /application/mysql-5.6.36/scripts/mysql_install_db:
【解决办法】
yum install -y perl-Module-Install.noarch
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux mysql