MariaDB (Debian): Unterschied zwischen den Versionen

Aus MattWiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:


== Connect to Server ==
== Connect to Server ==
  $ mysql -u user1 -p                    # Mit Passwortabfrage
  $ mysql -u user1 -p                    # Mit Passwortabfrage
  $ mysql -u user1 -ppassword1
  $ mysql -u user1 -ppassword1
Zeile 10: Zeile 11:


== Database Management ==
== Database Management ==
  show databases;                        # Datenbanken anzeigen
  show databases;                        # Datenbanken anzeigen
  show status;                            # Status of MySQL Server
  show status;                            # Status of MySQL Server
Zeile 16: Zeile 18:


== Table Management ==
== Table Management ==
  show tables;
  show tables;
  show table status;                      # Stats of all tables
  show table status;                      # Stats of all tables
Zeile 21: Zeile 24:


== User Management ==
== User Management ==
  show grants;                            # Show grants of current user
  show grants;                            # Show grants of current user
  show grants for user1                  # Show grants for user1
  show grants for user1                  # Show grants for user1


List users:  
List users:
  select user,host from mysql.user;
  select user,host from mysql.user;


Create user:  
Create user:
  create user 'username'@'localhost' identified by 'password';
  create user 'username'@'localhost' identified by 'password';


Remarks:
Remarks:
* localhost: User can connect only from (?) localhost
* localhost: User can connect only from (?) localhost
* %: User can connect on multiple hosts
* %: User can connect on multiple hosts


Grant all access to user1@localhost for * tables in database1:  
Grant all access to user1@localhost for * tables in database1:
  grant all on database1.* to user1@localhost;
  grant all on database1.* to user1@localhost;


== Backup Database ==
== Backup Database ==
  $ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
  $ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql


== Restore Database ==
== Restore Database ==
  $ mysql -u root -p[root_password] [database_name] < dumpfilename.sql
  $ mysql -u root -p[root_password] [database_name] < dumpfilename.sql


== Date and Time conversion ==


== Date and Time conversion ==
  select userid,from_unixtime(datefield) from table1;
  select userid,from_unixtime(datefield) from table1;
   
  <br>
  +-----------------------+----------------------------+
  +-----------------------+----------------------------+
  | userid                | from_unixtime(datefield)  |
  | userid                | from_unixtime(datefield)  |
Zeile 57: Zeile 64:


== Upgrade Database ==
== Upgrade Database ==


[[Category:Linux]]
[[Category:Linux]]
[[Category:Debian]]
[[Category:Debian]]

Version vom 22. Juli 2016, 22:56 Uhr

Diese Anleitungen gelten für:

  • MySQL 5.5
  • MariaDB 10.0

Connect to Server

$ mysql -u user1 -p                     # Mit Passwortabfrage
$ mysql -u user1 -ppassword1
exit                                    # Close connection

Database Management

show databases;                         # Datenbanken anzeigen
show status;                            # Status of MySQL Server
create database [database];             # Create new database
use [database];                         # Select Database

Table Management

show tables;
show table status;                      # Stats of all tables
describe [table];

User Management

show grants;                            # Show grants of current user
show grants for user1                   # Show grants for user1

List users:

select user,host from mysql.user;

Create user:

create user 'username'@'localhost' identified by 'password';

Remarks:

  • localhost: User can connect only from (?) localhost
  • %: User can connect on multiple hosts

Grant all access to user1@localhost for * tables in database1:

grant all on database1.* to user1@localhost;

Backup Database

$ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

Restore Database

$ mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Date and Time conversion

select userid,from_unixtime(datefield) from table1;

+-----------------------+----------------------------+ | userid | from_unixtime(datefield) | +-----------------------+----------------------------+ | user1 | 2016-05-01 19:30:00 | | user2 | 2016-05-02 12:55:00 | | user3 | 2016-05-03 21:03:00 | | user4 | 2016-05-04 23:27:00 | +-----------------------+----------------------------+

Upgrade Database