CentOS6.2下YUM安裝MySQL

用yum安裝MySqlmysql

  1. 打入以下命令:
    1. [root@mysql ~]# yum -y install mysql-server      //自動從網上搜索資源並自動下載安裝
  2. [root@mysql ~]# chkconfig mysqld on    //設置開機啓動MySql服務
    1. 檢查是否爲開機啓動
    2. 打入命令:[root@mysql ~]# chkconfig –list
    3. 看到:mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off 即表示已設置爲開機啓動,二、三、四、5爲on
  3. 啓動MySql服務
    1.  /etc/rc.d/init.d/mysqld start   //從文件啓動MySql服務
    2. service mysqld start            //以服務名方式啓動
 
MySql初始化環境設置(一)
  1. 設置MySQL的root用戶設置密碼,由於MySQL被安裝時,它的root用戶時沒有設置密碼的。
      [root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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>
2.       如上,默認是不須要密碼就能夠進入數據庫操做,下面查看MySQL數據庫用戶信息
 
 
MySql初始化環境設置(二)
  1. 打入命令:select user,host,password from mysql.user; //能夠看到密碼都爲空
      +------+-----------+----------+
      | user | host      | password |
      +------+-----------+----------+
      | root | localhost |          |
      | root | mysql     |          |
      | root | 127.0.0.1 |          |
      |      | localhost |          |
      |      | mysql     |          |
      +------+-----------+----------+
      5 rows in set (0.00 sec)
      set password for root@localhost=password(‘123456789’); //設置root用戶密碼爲123456789
 
 
MySql初始化環境設置(三)
       打入命令:select user,host,password from mysql.user; //查看剛設置的密碼,能夠看到密碼已經通過加密處理
      +------+-----------+-------------------------------------------+
      | user | host      | password                                  |
      +------+-----------+-------------------------------------------+
      | root | localhost | *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D |
      | root | mysql     |                                           |
      | root | 127.0.0.1 |                                           |
      |      | localhost |                                           |
      |      | mysql     |                                           |
      +------+-----------+-------------------------------------------+
      5 rows in set (0.00 sec)
       打入exit命令退出數據庫鏈接,測試root密碼是否生效
 
 
MySql初始化環境設置(四)
       打入命令:mysql –u root
      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root' at line 1
      彈出圖上提示說明剛設置的密碼已生效
       下面經過密碼登錄,打入命令:mysql –u root –p //在Enter password後輸入剛纔設置的密碼,看到下面即表示登錄成功
      [root@mysql ~]# mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor. Commands end with ; or \g.
      Your MySQL connection id is 3
      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; //查看系統已存在的數據庫
       use databasesname;   //選擇須要使用的數據庫
       drop database databasename; //刪除選定的數據庫
       exit    //退出數據庫的鏈接
       create database test01;    //創建名爲test的數據庫
      mysql> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | test               |
      | test01             |
      +--------------------+
      4 rows in set (0.00 sec)
        能夠看到新建的test01數據庫
       use test01;      //鏈接到數據庫test01
      mysql> use test01;
      Database changed
       mysql> create talbe test(num int,name varchar(50)); //在數據庫中創建表
      mysql> create table test(num int,name varchar(50));
      Query OK, 0 rows affected (0.11 sec)
       mysql> insert into test values(1,’Hello World!’) ;   //插入一個值到表中
      mysql> create table test(num int,name varchar(50));
      Query OK, 0 rows affected (0.11 sec)
       select * from test;   //查看數據庫中表的信息
       mysql> select * from test;
      +------+--------------+
      | num | name         |
      +------+--------------+
      |    1 | Hello World! |
      +------+--------------+
1 row in set (0.00 sec)
相關文章
相關標籤/搜索