liunx架构mysql操作

mysql相关配置

[[email protected] tmp]# vim /etc/my.cnf               //mysql的配置文件

[mysqld]

port            = 3306                              //端口

socket          = /tmp/mysql.sock                     //监听的sock

skip-locking                                         //过滤lock

key_buffer_size = 256M                               //索引块缓存

max_allowed_packet = 1M                           //允许最大的包

table_open_cache = 256                            //所有线程,打开表的数量

sort_buffer_size = 1M                             //排序缓冲区的大小

read_buffer_size = 1M                            //读缓冲区

read_rnd_buffer_size = 4M                        //随机读

myisam_sort_buffer_size = 64M                   //mysql引擎myisam

thread_cache_size = 8                          //缓存可重用线程数

query_cache_size= 16M                        //查询的缓存大小

thread_concurrency = 8                       //最大并发线程数

[mysqlhotcopy]

interactive-timeout=8                       //断开连接时间

wait_timeout=8

log_query_time=1                             //慢查询日志1S

log_slow_queries=/data/mysql/slow.log            //日志路径

mysql的root密码重置

[[email protected] tmp]# mysql -u root             //默认无密码即可登入

mysql> quit

Bye

[[email protected] tmp]# mysqladmin -u root password ‘abcd‘           //修改root的密码

[[email protected] tmp]# mysql -u root                         //无密码登入失败

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

[[email protected] tmp]# mysql -uroot -pabcd                 //使用密码登入

mysql> quit

Bye

现假设密码忘记,更改密码:

[[email protected] tmp]# vim /etc/my.cnf

[mysqld]

skip_grant                       //不用授权即可登入

[[email protected] tmp]# /etc/init.d/mysqld restart

[[email protected] tmp]# mysql                   //无需密码即可登入

mysql> use mysql

mysql> update user set password=password(‘123‘) where user=‘root‘;

//更改密码为123

mysql> select *from user where user=‘root‘\G

mysql> exit

Bye

[[email protected] tmp]# vim /etc/my.cnf

[mysqld]

#skip_grant               //注销掉,无需密码即可登入

[[email protected] tmp]# /etc/init.d/mysqld restart        //重启

[[email protected] tmp]# mysql -uroot -p123          //可登入,密码更改为123

mysql登入

[[email protected] ~]# mysql -uroot -p123

mysql> quit

Bye

[[email protected] ~]# mysql -uroot -h192.168.137.22  -P3306 -p123

ERROR 1130 (HY000): Host ‘192.168.137.22‘ is not allowed to connect to this MySQL server

//不通

[[email protected] ~]# telnet 192.168.137.22 3306

//查看该端口是否通,不通因为未授权

[[email protected] ~]# mysql -uroot -h127.0.0.1 -P3306 -p123      //可登入

mysql>

mysql> grant all on *.* to ‘root‘@‘192.168.137.22‘ identified by ‘123aaa‘;

mysql> use mysql;

mysql> select * from user where host=‘192.168.137.22‘;

mysql> select * from user where host=‘192.168.137.22‘\G;           //查看授权成功

[[email protected] ~]# mysql -uroot -h192.168.137.22 -P3306 -p123aaa

mysql>                           //可登入可远程登入mysql

mysql> select user();                   //查看当前登入用户

+---------------------+

| user()              |

+---------------------+

| [email protected] |

+---------------------+

1 row in set (0.00 sec)

[[email protected] ~]# mysql -uroot -S /tmp/mysql.sock -p

//本地存在多个mysql,用sock登入

Enter password:

mysql>

mysql常用操作:

[[email protected] ~]# mysql -uroot -p123              //登入

mysql>

mysql> show databases;

mysql> use mysql

mysql> use discuz

mysql> select database();

mysql> select user();

mysql> select version();

mysql> use discuz

mysql> show tables;

mysql> desc pre_ucenter_vars;

mysql> show create table pre_ucenter_vars\G;

mysql> desc pre_forum_post;

mysql> create database wang;

mysql> use wang;

mysql> create table tb1 (`id` int(4), `name` char(40)) ENGINE=MyISAM DEFAULT CHARSET=gbk;

mysql> show tables;

mysql> desc tb1;

mysql> show create table tb1\G;

mysql> insert into tb1 values(1,‘wang‘);

mysql> select *from tb1;

mysql> insert into tb1 values(2,‘cai‘);

mysql> select *from tb1;

+------+------+

| id   | name |

+------+------+

|    1 | wang |

|    2 | cai  |

+------+------+

mysql> insert into tb1 (`id`) values(2);

mysql> insert into tb1 (`name`) values(‘4‘);

mysql> select *from tb1;

+------+------+

| id   | name |

+------+------+

|    1 | wang |

|    2 | cai  |

|    2 | NULL |

| NULL | 4    |

+------+------+

mysql> insert into tb1(`name`,`id`) values(‘55‘,6);

mysql> select *from tb1;

+------+------+

| id   | name |

+------+------+

|    1 | wang |

|    2 | cai  |

|    2 | NULL |

| NULL | 4    |

|    6 | 55   |

+------+------+

5 rows in set (0.00 sec)

mysql> update tb1 set id=5 where name=‘55‘

mysql> select *from tb1;

+------+------+

| id   | name |

+------+------+

|    1 | wang |

|    2 | cai  |

|    2 | NULL |

| NULL | 4    |

|    5 | 55   |

+------+------+

5 rows in set (0.00 sec)

mysql> truncate table wang.tb1

mysql> drop table tb1;

mysql> drop database wang;

mysql> show databases;

mysql常用操作2

mysql> grant all on discuz .* to ‘user1‘@‘192.168.137.%‘ identified by ‘ccc‘;

mysql> flush privileges;

mysql> show processlist;

+----+------+-----------+------+---------+------+-------+------------------+

| Id | User | Host      | db   | Command | Time | State | Info             |

+----+------+-----------+------+---------+------+-------+------------------+

| 12 | root | localhost | NULL | Query   |    0 | NULL  | show processlist |

+----+------+-----------+------+---------+------+-------+------------------+

1 row in set (0.00 sec)

mysql> show variables;

mysql> set global max_connections=200;

mysql> show variables like ‘max_connec%‘;

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| max_connect_errors | 10    |

| max_connections    | 200   |

+--------------------+-------+

2 rows in set (0.00 sec)

mysql> set global max_connec_errors=100;

mysql> show variables like ‘max_connec%‘;

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| max_connect_errors | 100   |

| max_connections    | 200   |

+--------------------+-------+

2 rows in set (0.00 sec)

mysql> show status;

mysql> show status like ‘%running‘;

+-----------------+-------+

| Variable_name   | Value |

+-----------------+-------+

| Slave_running   | OFF   |

| Threads_running | 1     |

+-----------------+-------+

2 rows in set (0.00 sec)

mysql> quit

[[email protected] ~]# vim /etc/init.d/mysqld       //查看日志文件

basedir=/usr/local/mysql

datadir=/data/mysql

[[email protected] ~]# cd /data/mysql/

[[email protected] mysql]# ls

wangchao.err

[[email protected] mysql]# tail wangchao.err

[[email protected] mysql]# mysql -uroot -p123

mysql> repair table discuz.pre_forum_post;                  //修复表

+-----------------------+--------+----------+----------+

| Table                 | Op     | Msg_type | Msg_text |

+-----------------------+--------+----------+----------+

| discuz.pre_forum_post | repair | status   | OK       |

+-----------------------+--------+----------+----------+

1 row in set (0.04 sec)

mysql备份操作

[[email protected] ~]# mysqldump -uroot -p123 discuz   //查看备份内容

[[email protected] ~]# mysqldump -uroot -p123 discuz >/data/discuz.sql

[[email protected] ~]# vim /data/discuz.sql

[[email protected] ~]# cd /data/mysql/

[[email protected] mysql]# ls

[[email protected] mysql]# cd discuz/

[[email protected] discuz]# rm -rf pre_forum_post*

//删除数据表,备份库

[[email protected] discuz]# mysql -uroot -p123 discuz </data/discuz.sql

//恢复数据,恢复库

[[email protected] discuz]# mysqldump -uroot -p123 discuz pre_forum_post >/data/post.sql;

//备份一个表

[[email protected] discuz]# cat /data/post.sql

[[email protected] discuz]# mysql -uroot -p123 discuz </data/post.sql

//恢复一个表

[[email protected] discuz]#  mysqldump -uroot  --default-character-set=gbk -p123 discuz pre_forum_post >/data/post.sql

//备份(一个表)时指定字符集,指定字符集防止一些出错的问题

[[email protected] discuz]#  mysqldump -uroot  --default-character-set=gbk -p123 discuz pre_forum_post </data/post.sql

//恢复

时间: 2024-10-13 20:23:53

liunx架构mysql操作的相关文章

docker mysql 容器报too many connections 引发的liunx磁盘扩容操作

症状每次删除mysql容器重启没两分钟又报标题错 df -h 命令查看各个挂载空间应用情况发现root home var 三个文件目录挂载的空间满了 网上百度了一下liunx磁盘扩容操作,fdisk -l 命令最终发现本机有一块270的磁盘并未挂载 于是创建pv ,通过pvcreate命令将磁盘/dev/xvdb创建为一个系统PV [[email protected] home]# pvcreate /dev/xvdb Physical volume "/dev/xvdb" succe

数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

一.MySQL MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换 服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失败之后需要手动恢复主从架构 MySQL中型高可用架构 方案:MMM + MySQL双主 + 多从高可用方案 服务器资源: 1.至少五台PC Server,2台MySQL主库,2台MySQL从库,1台MMM Monitor: 2.1台MMM Monitor选择低配: 3.如果不采用F5作为从库的负载均衡器

[转]数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

一.MySQL MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换 服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失败之后需要手动恢复主从架构 MySQL中型高可用架构 方案:MMM + MySQL双主 + 多从高可用方案 服务器资源: 1.至少五台PC Server,2台MySQL主库,2台MySQL从库,1台MMM Monitor: 2.1台MMM Monitor选择低配: 3.如果不采用F5作为从库的负载均衡器

Mysql操作初级

Mysql操作初级 本节内容 数据库概述 数据库安装 数据库操作 数据表操作 表内容操作 1.数据库概述 数据库管理系统叫做DBMS 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL Server等 ? 答:他们均是一个软件,都有两个主要的功能: a. 将数据保存到文件或内存 b. 接收特定的命令,然后对文件进行相应的操作 PS:如果有了以上软件,无须自己再去创建文件

php 的mysql操作类

亲自测试,网上其他版本没法用,有很多错误,这是本人亲自测试用的,绝对增删改查都可以. <?php /** * Created by Netbeans. * User: Lugo * Date: 16-7-14 * Version: 1.0.0 * Time: 上午10:50 */ class MysqlHelper { const HOST="localhost"; const DATABASE = "demo"; const ENCODING = "

mysql热备及查询mysql操作日志

mysql热备 1 查看mysql版本,保证主库低于等于从库 2 主库配置:   A 需要打开支持日志功能:log-bin=mysql-bin   B 提供server-id:server-id=1   C 重启mysql,进入后,分配复制从库的帐号 GRANT REPLICATION SLAVE ON *.* TO 'repuser'@'backip' IDENTIFIED BY 'repuser';   D show master status;能看到二进制日志文件目前的Position  

ecshop的Mysql操作类

摘要,这是直接摘抄的ecshop的mysql操作类:不过他这里的缓存是用的文件缓存,我们如果想直接使用,可以替换成memcache的或者redis的! <?php /** * ECSHOP MYSQL 公用类库 * ============================================================================ * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利. * 网站地址: http://www.ecsho

BS架构数据库操作必备

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; using System.Data.SqlClient; using System.Data; using System.Web.UI.WebControls; using System.Windows.Forms; using System.Collections; //using Sys

Python MySql 操作类

Python 2.7 暂时只用到这么多,以后用到其他的再补充. # -*- coding:utf-8 -*- import MySQLdb import time ''' · MySQL 操作类 · V1.0 ''' class MySQLClass(object): def __init__(self,host,user,password,charset="utf8"): super(MySQLClass, self).__init__() self.host=host self.u