yum remove -y mysql
7.启动mysql
cd /export/servers/mysql
cp support-files/mysql.server /etc/init.d/mysqld
检查配置文件的datadir,basedir等是否正确
service mysqld start 8.检查mysql是否启动成功
ps -ef |grep mysql
netstat -lnp |grep mysql
9.如果启动不了,就在/export/Data/mysql/data找`hostname`.err对应的日志查看 Mysql常用操作
·授权超级用户:
·grant all privileges on *.* to 'fengxiaoqing'@'%'> ·查看库:
·show databases;
·查看都有哪些库 show databases;
·查看某个库的表 use db; show tables \G;
·查看表的字段 desc tb;
·查看建表语句 show create table tb;
·当前是哪个用户 select user();
·当前库 select database();
·创建库 create database db1;
·创建表 create table t1 (id int, name char(40) adress varchar(30));
·char(10) 'aaa '
·varchar(10) 'aaa'
·查看数据库版本 select version();
·查看mysql状态 show status;
·修改mysql参数 show variables like 'max_connect%'; set global max_connect_errors = 1000;
·查看mysql队列 show processlist;
·select * from information_schema.processlist where info is not null;
·sleep的可以忽略,qurey查询的才有
·创建普通用户并授权 grant all on *.* to databases1.user1>
·grant all on db1.* to 'user2'@'10.0.2.100'>
·grant all on db1.* to 'user3'@'%'> ·更改密码 UPDATE mysql.user SET password=PASSWORD("newpwd") WHERE user='username' ;
·查询 select count(*) from mysql.user; select * from mysql.db; select * from mysql.db where host like '10.0.%';
·插入 update db1.t1 set name='aaa' where> ·清空表 truncate table db1.t1;
·删除表 drop table db1.t1;
·删除数据库 drop database db1;
·修复表 repair table tb1 [use frm];
·查看权限show grants for root@'localhost';
·echo "select user,host,password from mysql.user" |mysql -uroot -p123456
·mysql -uroot -p1234556 -e "select user,host,password into outfile '/home/mysql/1.txt' from mysql.user;" Mysql的连接
·1.创建数据库 create database python;
·2. 授权用户
·grant all privileges on *.* to feng@’%’> ·flush privilege;
·conn=MySQLdb.connect(host="192.168.100.101",user="feng",passwd="123456",db="python",charset="utf8") 比较常用的参数包括:
·host:数据库主机名.默认是用本地主机
·user:数据库登陆名.默认是当前用户
·passwd:数据库登陆的秘密.默认为空
·db:要使用的数据库名.没有默认值
·port:MySQL服务使用的TCP端口.默认是3306,数字类型
·charset:数据库编码
推荐大家使用函数的方式:
def connect_mysql(): db_config = {
'host': '192.168.48.128',