Centos6.5 mysql折腾记

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



 1 [mysqld]
2 datadir=/var/lib/mysql
3 socket=/var/lib/mysql/mysql.sock
4 user=mysql
5 #最重要的下面这一行代码
6 skip-grant-tables
7 # Disabling symbolic-links is recommended to prevent assorted security risks
8 symbolic-links=0
9
10 [mysqld_safe]
11 log-error=/var/log/mysqld.log
12 pid-file=/var/run/mysqld/mysqld.pid


4.2.2、重启MySql



[root@localhost ~]# service mysqld restart


4.2.3、修改密码



1 [root@localhost ~]# mysql -u root
2 mysql> use mysql;
3 mysql> set password for root@localhost=password('root');
4 mysql> flush privileges;
5 mysql> exit;
6 [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常用命令



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


4.5、MySQL开放远程登陆权限



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

0 个评论

要回复文章请先登录注册