Rotinas básicas no mysql – GRANT ALL PRIVILEGES | CREATE USER | DROP USER | RENAME COLUMN

Criar um usuário no mysql:

1
CREATE USER 'novousuario'@'localhost' IDENTIFIED BY 'password';

Permissão a um determiando banco:

1
GRANT ALL PRIVILEGES ON * . * TO 'novousuario'@'localhost';

Alterações em vigor:

1
FLUSH PRIVILEGES;

Apagar usuário:

1
DROP USER Nome_Usuario;

Renomear Colunas

1
ALTER TABLE nome_tabela CHANGE nome_velho nome_novo TEXT;

Atualizar tabela a partir de um SELECT e INNER JOIN

1
UPDATE tabela1 INNER JOIN tabela2 ON tabela1.usuario_id = tabela2.usuario_id SET tabela1.id = tabela2.id;

2 comentários sobre “Rotinas básicas no mysql – GRANT ALL PRIVILEGES | CREATE USER | DROP USER | RENAME COLUMN

  1. Add a column to an existing MySQL table
    Posted February 8, 2004 by Quinn McHenry in MySQL
    MySQL tables are easy to extend with additional columns.

    To add a column called email to the contacts table created in Create a basic MySQL table with a datatype of VARCHAR(80), use the following SQL statement:

    ALTER TABLE contacts ADD email VARCHAR(60);

    This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

    ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;

    If you want the new column to be first, use this statement:

    ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

  2. Delete a column from an existing MySQL table
    Posted March 18, 2004 by Quinn McHenry in MySQL
    The SQL command in this recipe removes a column and the column’s data from an existing MySQL table.

    To delete the column col_stuff from the table table_things, use the following SQL command:

    ALTER TABLE ‘table_things’ DROP ‘col_stuff’

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *