mysql安装等操作

CentOS 6.5系统中安装配置MySQL数据库


卸载掉原有mysql

rpm -qa | grep mysql  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库

rpm -e mysql  // 普通删除模式

rpm -e --nodeps mysql  // 强力删除模式

rpm -qa | grep mysql   //命令来查看mysql是否已经卸载成功

注意:安装mysql时我们并不是安装了mysql客户端就相当于安装好了mysql数据库了,我们还需要安装mysql-server服务端才行

root-shell> yum -y install mysql mysql-server mysql-libs

安装完成后,了解mysql数据库的初始化及相关配置

root-shell> service mysqld start

 //初始化 MySQL 数据,这时我们会看到第一次启动mysql服务器以后会提示非常多的信息,目的就是对mysql数据库进行初始化操作,当我们再次重新启动mysql服务时,就不会提示这么多信息了

service mysqld restart

chkconfig --list | grep mysqld

chkconfig mysqld on  //设置开机启动

mysqladmin -u root password 'root'  // 通过该命令给root账号设置密码为 root

 mysql -u root -p  // 命令来登录我们的mysql数据库了

数据库的主要配置如下:

/etc/my.cnf   这是mysql的主配置文件

/ver/lib/mysql     mysql数据库的数据库文件存放位置

/var/log mysql  数据库的日志输出存放位置

mysql数据库绑定的端口号是 3306

netstat -anp | more

navicat进行连接会显示连接错误。

# mysql -u root -p  
mysql> use mysql;  

mysql> select 'host' from user where user='root';  

mysql> update user set host = '%' where user ='root';  #其中执行这句会报错,不管它

mysql> flush privileges;  

mysql> select 'host' from user where user='root'; 

mysql>quit;

再次用navicat打开连接成功。

#对应中文翻译 

第一句:以权限用户root登录  

第二句:选择mysql库  

第三句:查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)  

第四句:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址  

第五句:刷新MySQL的系统权限相关表  

第六句:再重新查看user表时,有修改。。  

重起mysql服务即可完成。


忘记mysql数据库root用户密码:

修改MySQL的登录设置

方法一(实验没有成功):

vi /etc/my.cnf 

加入:skip-grant-tables

重新启动mysqld 

/etc/init.d/mysqld restart
mysql> USE mysql ;

mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;

mysql>flush privileges ;

mysql> quit
#vi /etc/my.cnf
//重新启动mysqld 
# /etc/init.d/mysqld restart

方法二(实验成功):

1、首先关闭mysql

# /etc/init.d/mysqld stop
2、后台启动mysql
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
//注意我们加了--skip-networking,避免远程无密码登录MySQL。
登陆mysql
# mysql -u root mysql
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('root') where USER='root' and host='root' or host='localhost';
mysql> FLUSH PRIVILEGES;
mysql > quit
启动mysql,并登陆
# /etc/init.d/mysqld restart
# mysql -u root -p
输入密码:root
登陆成功如下:
[root@trs ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
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>
原文地址:https://www.cnblogs.com/Bourke/p/5775808.html