Centos6.5 mysql折腾记

时间:2023-10-04 12:52:13

1、yum安装mysql

[root@localhost ~]# yum -y install mysql-server

安装结果

Installed:
  mysql-server.x86_64 0:5.1.73-7.el6                                                            

Dependency Installed:
  mysql.x86_64 0:5.1.73-7.el6                perl-DBD-MySQL.x86_64 0:4.013-3.el6               

Complete!

2、设置开机启动

[root@localhost ~]# chkconfig mysqld on

3、MySQL服务

3.1、MySQL服务开启

[root@localhost ~]# service mysqld start

3.2、MySQL服务关闭

[root@localhost ~]# service mysqld stop

3.1、MySQL服务重启

[root@localhost ~]# service mysqld restart

4、MySQL密码

4.1、设置密码

[root@stonex ~]#  mysql -u root
mysql> set password for root@localhost=password('root');
mysql> exit

4.2、密码忘记

4.2.1、修改/etc/my.cnf

 [mysqld]
 datadir=/var/lib/mysql
 socket=/var/lib/mysql/mysql.sock
 user=mysql
 #最重要的下面这一行代码
 skip-grant-tables
 # Disabling symbolic-links is recommended to prevent assorted security risks
 symbolic-links=0

 [mysqld_safe]
 log-error=/var/log/mysqld.log
 pid-file=/var/run/mysqld/mysqld.pid

4.2.2、重启MySql

[root@localhost ~]# service mysqld restart

4.2.3、修改密码

 [root@localhost ~]# mysql -u root
 mysql> use mysql;
 mysql> set password for root@localhost=password('root');
 mysql> flush privileges;
 mysql> exit;
 [root@localhost ~]# service mysqld restart

4.2.4、修改/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4.3、MySQL登陆

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

4.4、MySQL常用命令

 show databases; //查看系统已存在的数据库
 use databasesname;   //选择需要使用的数据库
 drop database databasename; //删除选定的数据库
 exit    //退出数据库的连接
 create database test01;    //建立名为test的数据库
 show tables;        // 列出当前数据库下的表
 其他基本的增删改查使用标准SQL即可

4.5、MySQL开放远程登陆权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;