Linux中关于mysql查看安装目录与是否安装等问题

本文详细介绍在Linux环境下如何查看MySQL和Apache是否已安装,包括使用ps、grep、rpm等命令的方法。同时,提供了启动、停止、重启MySQL服务的具体步骤,并介绍了如何在Linux下卸载MySQL。此外,文章还讲解了如何查看MySQL的安装路径和运行文件位置。

Linux下查看mysql、apache是否安装,并卸载。

指令 ps -ef|grep mysql 得出结果

root 17659 1 0 2011 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
mysql 17719 17659 0 2011 ? 03:14:57 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
usr/bin/mysql 是指:mysql的运行路径
var/lib/mysql 是指:mysql数据库文件的存放路径
usr/lib/mysql 是指:mysql的安装路径

1,mysql 的守护进程是mysqld

如果已经安装则:

[root@localhost ~]# service mysqld start
启动 MySQL: [确定]

如果没有安装则:

[root@localhost ~]# service mysqld start
mysqld:未被识别的服务

你可以看看你的服务是否已经添加到linux上

[root@localhost ~]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:启用 6:关闭

没有安装则:
[root@localhost ~]# chkconfig --list mysqld
在mysqld服务中读取信息时出错,没有那个文件或目录

一旦你启动了服务,可以这样检查服务器是否在运行

[root@localhost ~]# ps -el | grep mysqld
4 S 0 1796 1 0 85 0 - 1513 wait ? 00:00:00 mysqld_safe
4 S 27 1856 1796 0 78 0 - 34055 - ? 00:00:00 mysqld
[root@localhost ~]#
如果你看到有,就说明服务器安装起来了~~

linux下查看apache是否安装及版本

如通是通过rpm包安装的话直接用下面的命令:
rpm -q httpd

也可以使用如下两种方法:
httpd -v

apachectl -v

linux下卸载mysql方法

a. 查找已安装的myslq 版本:
#rpm -qa | grep mysql (注意大小写,如果mysql 不行就换MySQL)

显示:
[root@localhost ~]# rpm -qa | grep mysql
mysql-5.0.77-4.el5_4.2
mysql-server-5.0.77-4.el5_4.2
php-mysql-5.2.13-1.el5.art
复制代码
在屏幕上将显示已安装的mysql包名如:mysql-5.0.77-4.el5_4.2 ;

将搜索出的包名卸载:

#rpm -e –nodeps mysql-5.0.77-4.el5_4.2 (nodeps表示强制删除)

提示
error: package –nodeps is not installed
error: package mysql-.0.77-4.e15_.2 is not installed

Linux查看mysql 安装路径

一、查看文件安装路径

由于软件安装的地方不止一个地方,所有先说查看文件安装的所有路径(地址)。

这里以mysql为例。比如说我安装了mysql,但是不知道文件都安装在哪些地方、放在哪些文件夹里,可以用下面的命令查看所有的文件路径
在终端输入:

whereis mysql

回车,如果你安装好了mysql,就会显示文件安装的地址,例如我的显示(安装地址可能会不同)

[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

二、查询运行文件所在路径(文件夹地址)

如果你只要查询文件的运行文件所在地址,直接用下面的命令就可以了(还是以mysql为例):

which mysql

终端显示:

[root@localhost ~]# which mysql
/usr/bin/mysql

Linux关于mysql的启动与停止:
一、启动方式

1、使用 service 启动:service mysqld start
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start

二、停止

1、使用 service 启动:service mysqld stop
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop

三、重启
1、使用 service 启动:service mysqld restart
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
[root@localhost ~]# mysql -uroot -p123

四、阿里云Linux看不到mysql用户登录表的数据库的解决方案:

Welcome to the MySQL monitor. Commands endwith ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear thebuffer.

mysql>show databases;

±-------------------+
|Database |
±-------------------+
| information_schema |
|test |
±-------------------+

只显示这个两个数据库,看不到mysql数据库

解决方法:

此问题实际上是用户没有权限:

  1. 关闭mysql,service mysqld stop

  2. 启动mysql: mysqld_safe --skip-grant-tables

  3. 再打开一个ssh连接服务器,进行mysql操作

    [root@localhost ~]#mysql

Welcome to the MySQL monitor. Commands endwith ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear thebuffer.

mysql>show databases;

在这个模式下是可以看到mysql数据库的。

在数据库名mysql下的user表中,修改相应权限,比如:

INSERT INTO user values (‘localhost’, ‘root’, “这里是自己的密码”, ‘Y’, ‘Y’, ‘Y’,‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’,‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’,’’, ‘’, ‘’, ‘’, ‘0’, ‘0’, ‘0’, ‘0’, ‘’, ‘’);

如果已经存在了host为localhost的记录,则先删除该记录,delete from user wherehost=‘localhost’;

然后再进行

INSERT INTO user values (‘localhost’, ‘root’, “这里是自己的密码”, ‘Y’, ‘Y’, ‘Y’,‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’,‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’,’’, ‘’, ‘’, ‘’, ‘0’, ‘0’, ‘0’, ‘0’, ‘’, ‘’);

操作。

操作完成后,将两个ssh连接都关闭,然后再重新连接一个ssh,启动mysql,service mysqldstart,然后用mysql命令连接mysql数据库

[root@localhost ~]#mysql -uroot -p

密码为空。

[如果此时还连接不上,再重启一下mysql就好了,service mysqldrestart]。

然后就可以用 [root@localhost ~]#mysqladmin -urootpassword ‘newpassword’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值