欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL/MariaDBSQL修改表字段类型、备份数据库

程序员文章站 2022-04-12 21:22:54
1、修改表字段类型 alter table nodes modify column info varchar(200) 示例操作入下: MariaDB [dbmanage...

1、修改表字段类型

alter table nodes modify column info varchar(200)

示例操作入下:

MariaDB [dbmanager]> alter table nodes modify column info varchar(200);
Query OK, 0 rows affected (0.02 sec)               
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [dbmanager]> desc nodes;
+-----------+--------------+------+-----+---------------------+-------------------------------+
| Field     | Type         | Null | Key | Default             | Extra                         |
+-----------+--------------+------+-----+---------------------+-------------------------------+
| id        | varchar(36)  | NO   | PRI | NULL                |                               |
| nodename  | varchar(20)  | YES  |     | NULL                |                               |
| ip        | varchar(20)  | YES  |     | NULL                |                               |
| username  | varchar(20)  | YES  |     | NULL                |                               |
| password  | varchar(20)  | YES  |     | NULL                |                               |
| os        | varchar(20)  | YES  |     | NULL                |                               |
| pubkey    | varchar(400) | YES  |     | NULL                |                               |
| role      | varchar(100) | YES  |     | NULL                |                               |                              |
| sn        | int(10)      | YES  |     | NULL                |                               |
| info      | varchar(200) | YES  |     | NULL                |                               |
| status    | int(10)      | YES  |     | NULL                |                               |                           |
+-----------+--------------+------+-----+---------------------+-------------------------------+
14 rows in set (0.01 sec)

MariaDB [dbmanager]> 

2、备份数据库

mysqldump -h hostname -uroot -p dbname > /root/sql/bak.sql

示例操作

[root@hadron ~]# mysqldump -h master -uroot -p123456 dbmanager > /root/sql/bak.sql
[root@hadron ~]# ll sql|grep bak.sql
-rw-r--r-- 1 root root 25908 11月 28 09:34 bak.sql
[root@hadron ~]#