我在购买了一台装centos系统的阿里云服务器,发现上面已经为我安装好了MySql数据库 (适用于其他linux系统,如自己装的centos)
1.阿里云centOS自带mysql装在哪?
一开始你可能没发现,如何发现呢?如下指令:
rpm -qa |grep mysql
结果如下:
[root@iZ2zee5k72y8t2ep1of2pfZ ~]# rpm -qa |grep mysql
mysql-libs-5.1.73-7.el6.x86_64
[root@iZ2zee5k72y8t2ep1of2pfZ ~]#
可见,系统已经有了,如果没有结果说明没装,如果装了,那么如何找到其目录呢?
这样这样做:
# find / -name mysql
得到结果如下:
/usr/local/mysql
/usr/local/mysql/include/mysql
/usr/local/mysql/bin/mysql
/usr/share/mysql
/usr/lib64/mysql
/data/mysql
/data/mysql/mysql
/var/lock/subsys/mysql
/var/spool/mail/mysql
可见,阿里云服务器中将mysql装再来/usr/local目录下。
2. contos系统默认安装mysql client,没有mysqld
一般你会发现contos系统默认好像装了mysql,但始终找不到密码,也不能登上,强制更改root密码时发现根本没有mysqld,这可能是因为contos默认只装了mysql client。
在Centos中用命令 yum install mysql安装数据库,但装完后运行mysqld启动mysql的时候提示找不到,通过 find / | grep mysqld 也没找到mysqld的目录,后来在Google上搜索下,才知道用yum安装时候mysql也有三个参数的。
yum install mysql,只是安装了mysql的client,如果你只安装了这一步,就会发现找不到mysqld。
yum install mysql-server,才安装了mysql的服务后台程序;当然还有一个MySQL-devel。
装上后就有mysqld了。
具体步骤如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
yum install mysql yum install mysql-server yum install mysql-devel chgrp -R mysql /var/lib/mysql chmod -R 770 /var/lib/mysql service mysqld start To start mysqld at boot time you have to copy support-files /mysql .server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h LAMP.ORG password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql- test -run.pl cd mysql- test ; perl mysql- test -run.pl Please report any problems with the /usr/bin/mysqlbug script! The latest information about MySQL is available on the web at http: //www .mysql.com Support MySQL by buying support /licenses at http: //shop .mysql.comz |
3. 阿里云centOS自带mysql等不进去,怎么办?[如何强制修改root方法]
说道这个有点坑,在mysql5.6之后的版本将在第一次运行mysql是产生一个随机密码。文件名.mysql_secret中。通常在/root/.mysql_secret 下
可参考这篇文章
http://blog.csdn.net/it_faquir/article/details/50850302
可是你会发现并没有,那么好吧,试试看,用户名:root, 密码:空密码、root、admin、123546,都不行,怎么登都进去,那怎么办?
那只能暴力点了。如下方法
首先移动到根目录
cd /etc
然后用vi打开配置文件
vi my.cnf
使用hjkl(左 下 上 右)移动光标
找到[mysqld]的段,使光标停留在段中任意处
按下o(进入插入模式并从新的一行开始输入)
使用键盘输入
skip-grant-tables
按下键盘的冒号“:”(返回底行模式),并输入wq(表示保存并退出)按回车。
关于vi命令更多指令请百度,这里只写了用到的,请严格操作不要按错
重启mysql,在终端输入
service mysqld restart
重启后配置生效,就在也不用密码了,相对于越过了认证,登录用户
mysql -u root -p
遇到密码直接按回车
登录后在mysql界面下,继续如下语句,进行密码修改
use mysql
update user set password=password("123") where user="root";
最后保存更改
flush privileges;(刷新权限)
exit;
再次用vi打开配置文件
vi my.cnf
将之前的skip-grant-tables删除即可。
“:wq”保存
最后再重启下
service mysqld restart
OK,搞定,可以登录了。
整理自:
http://blog.csdn.net/IT_faquir/article/details/75195118?locationNum=2&fps=1
https://www.magentonotes.com/centos-yum-install-mysql-and-mysqld.html