先建立使用者和使用者組
su - root
groupadd mysql
useradd -g mysql mysql
解壓二進位檔案。
gunzip -c filename | tar -xf -
複製目錄/home/mysql到/usr/local;
建立mysql許可表:
linux:/usr/local/mysql #scripts/mysql_install_db --user=mysql
設定二進位所有權,使之歸root所有,並屬於mysql所在管理組:
linux:/usr/local/mysql # chown -R root /usr/local/mysql
linux:/usr/local/mysql # chgrp -R mysql/usr/local/mysql
將資料目錄的所有權設定為mysql系統管理使用者:
linux:/usr/local/mysql # chown -R mysql /usr/local/mysql/data
啟動伺服器:
linux:/usr/local/mysql # bin/mysqld_safe --user=mysql &
登入:
linux:/usr/local/mysql # bin/mysql -u mysql
mysql>show databases;
最初只有兩個:test,information_schema;
以root身份登入則有四個。
運行命令bin/mysql -u root -p,此時將出現password:(要求輸入密碼),但預設情況下root使用者沒有密碼,所以斷行符號即可。此時將進入MySQL介面,當然仍然只是個命令列視窗而以。
運行命令use test,將進入test資料庫
mysql>use test;
mysql> show tables
-> ;
Empty set (0.00 sec)
建立一個地址簿資料庫:
mysql> create database address;
mysql> use address;
Database changed
建立表:
mysql> create table friends (name Char(15),telphone VarChar(20),qq Char(10), address VarChar(30));
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 'create table friends (name Char(15),telphone VarChar(20),qq Char(10), address ' at line 1
mysql> create table friends (name Char(15),telphone VarChar(20),qq Char(10), address VarChar(30));
Query OK, 0 rows affected (0.01 sec)
新增幾筆資料,並查詢看看:
mysql> insert into friends values("xyf","123456","359830463","浙江");
Query OK, 1 row affected (0.00 sec)
mysql> insert into friends values
-> (
-> "myblue",
-> "6743133"
-> ,"464313113",
-> "zhejiang");
Query OK, 1 row affected (0.00 sec)
mysql> select * from friends;
+--------+----------+-----------+----------+
| name | telphone | qq | address |
+--------+----------+-----------+----------+
| xyf | 123456 | 359830463 | 浙江 |
| myblue | 6743133 | 464313113 | zhejiang |
+--------+----------+-----------+----------+
2 rows in set (0.00 sec)
建立和修改密碼:
#在控制台上輸入
linux:/usr/local/mysql # bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.12-beta MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> update user set password=password('1234') where user='root';
mysql> FLUSH PRIVILEGES;
mysql> exit
Bye
linux:/usr/local/mysql # bin/mysql -u root -p1234
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.1.12-beta MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>