• MySQL基本管理和应用


    # yum install mysql-server

    # /etc/init.d/mysqld start
    Initializing MySQL database: Installing MySQL system tables...
    OK
    Filling help tables...
    OK

    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h CentOS1.eric.com password 'new-password'

    Alternatively you can run:
    /usr/bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default. This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:
    cd /usr ; /usr/bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl
    cd /usr/mysql-test ; perl mysql-test-run.pl

    Please report any problems with the /usr/bin/mysqlbug script!

    ============================================================================================================================================
    # mysqladmin -u root password 'password'
    # mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.1.61 Source distribution

    Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | test |
    +--------------------+
    3 rows in set (0.00 sec)

    mysql> create database wordpress;
    Query OK, 1 row affected (0.02 sec)

    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | test |
    | wordpress |
    +--------------------+
    4 rows in set (0.00 sec)
    mysql> GRANT ALL PRIVILEGES ON *.* to 'wordpress'@'localhost' IDENTIFIED BY 'wordpress' WITH GRANT OPTION;
    Query OK, 0 rows affected (0.00 sec)


    mysql> create database bank;
    Query OK, 1 row affected (0.00 sec)

    mysql> create database shop;
    Query OK, 1 row affected (0.00 sec)

    mysql> create database hospital;
    Query OK, 1 row affected (0.01 sec)


    mysql> grant select,insert,update,delete,create,drop
    -> on bank.*
    -> to 'custom'@'localhost'
    -> identified by 'obscure';
    Query OK, 0 rows affected (0.00 sec)

    mysql> grant select,insert,update,delete,create,drop on shop.* to 'custom'@'localhost' identified by 'obscure';
    Query OK, 0 rows affected (0.00 sec)

    mysql> grant select,insert,update,delete,create,drop on hospital.* to 'custom'@'localhost' identified by 'obscure';
    Query OK, 0 rows affected (0.00 sec)
    ============================================================================================================================================
    # mysql bank -u custom -p
    mysql> use bank;
    mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
    Query OK, 0 rows affected (0.03 sec)
    mysql> show tables;
    +----------------+
    | Tables_in_bank |
    +----------------+
    | pet |
    +----------------+
    1 row in set (0.00 sec)

    mysql> DESC pet;
    +---------+-------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +---------+-------------+------+-----+---------+-------+
    | name | varchar(20) | YES | | NULL | |
    | owner | varchar(20) | YES | | NULL | |
    | species | varchar(20) | YES | | NULL | |
    | sex | char(1) | YES | | NULL | |
    | birth | date | YES | | NULL | |
    | death | date | YES | | NULL | |
    +---------+-------------+------+-----+---------+-------+
    6 rows in set (0.00 sec)

    mysql> insert into pet values ('Puffball','Diane','hamster','f','2001-02-01',NULL);
    Query OK, 1 row affected (0.01 sec)
    mysql> insert into pet values ('Puffbffff','eric','hamster','f','2022-02-01',NULL);
    Query OK, 1 row affected (0.00 sec)
    mysql> insert into pet values ('Pub','laszy','hamster','f','2222-02-01',NULL);
    Query OK, 1 row affected (0.00 sec)

    mysql> select * from pet;
    +-----------+-------+---------+------+------------+-------+
    | name | owner | species | sex | birth | death |
    +-----------+-------+---------+------+------------+-------+
    | Puffball | Diane | hamster | f | 2001-02-01 | NULL |
    | Puffbffff | eric | hamster | f | 2022-02-01 | NULL |
    | Pub | laszy | hamster | f | 2222-02-01 | NULL |
    +-----------+-------+---------+------+------------+-------+
    3 rows in set (0.00 sec)


    mysql> select * from pet where name='Pub';
    +------+-------+---------+------+------------+-------+
    | name | owner | species | sex | birth | death |
    +------+-------+---------+------+------------+-------+
    | Pub | laszy | hamster | f | 2222-02-01 | NULL |
    +------+-------+---------+------+------------+-------+
    1 row in set (0.00 sec)

    mysql> select name, owner from pet;
    +-----------+-------+
    | name | owner |
    +-----------+-------+
    | Puffball | Diane |
    | Puffbffff | eric |
    | Pub | laszy |
    +-----------+-------+
    3 rows in set (0.00 sec)

  • 相关阅读:
    分部视图
    linq的几个方法
    如何让服务器支持mp4文件下载和sqlserver将表生成为sql语句方法
    在asp.net mvc中导出Excel文件
    Linq2EF操作中的两个小问题
    JSON到底是什么?
    连接跟踪(conntrack):原理、应用及 Linux 内核实现 转载
    没有安全,没有隐私
    互联网发展到今天,我们要做的,是用机器解决人类解决不了的问题。在这个意义上,比起人工智能,机器智能这个词更加准确。
    今天,世界各国城市的可持续发展面临很大挑战,这些挑战也带来了一个难得的机遇,就是利用机器智能解决城市发展过程中许多重要的问题,如交通治理。同时这也是像机器智能这样的新一代技术快速发展的机遇,这正是我全身心推动城市大脑的原因
  • 原文地址:https://www.cnblogs.com/oskb/p/3848619.html
Copyright © 2020-2023  润新知