機房mysql數據庫幾乎全部是用編譯方式安裝,要注意的是,你優化的項越多,編譯過程就越長。以下是編譯步驟,按下文一步步走,不會出任何差錯。
安裝之前,請解決和確認最根本的依賴關係:C環境
MYSQL 5 :
tar zxvf mysql-5.1.44.tar.gz
cd mysql-5.1.44
./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql --enable-thread-safe-client --enable-local-infile --with-extra-charsets=all --with-low-memory --without-server --enable-assembler --with-big-tables --with-readline --with-ssl --with-embedded-server --with-innodb --with-charset=utf8 --with-extra-charsets=gb2312 --with-federated-storage-engine --with-plugins=innobase --without-debug --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
可能會出現的錯誤:
checking for termcap functions library... configure: error: No curses/termcap library found
解決方法:
ncurses-devel.***.rpm 包解決
或者去下載一個ncurses-5.6.tar.gz,
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure –prefix=/usr –with-shared –without-debug
make
make install clean
然後再重新編譯Mysql進行安裝。
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
這裏介紹configure的幾個參數
--prefix=PREFIX //mysql的安裝路徑
--sysconfdir=DIR //mysql的系統配置文件,也就是my.cnf
--localedir=DIR //數據庫存放位置
--prefix=/opt/mysql 將MySQL安裝到目錄/opt/mysql下
--with-charset=utf8 指定缺省字符集爲utf8
--with-extra-charsets=all 將MySQL所有支持的字符集編譯進來
--with-tcp-port=3306 指定此MySQL實例將監聽TCP 3306端口
--with-unix-socket-path=/tmp/mysql.sock 指定UNIX socket文件的路徑(爲絕對路徑)
--wih-mysqld-user=mysqld 指定用來運行MySQL守護進程的用戶
--with-federated-storage-engine 支持federated存儲引擎
--with-plugins=innobase 支持innobase數據庫(5.1+,默認爲空)
--without-debug \去除debug模式
--with-extra-charsets=gb2312 \添加gb2312中文字符支持
--enable-assembler \使用一些字符函數的彙編版本
--without-isam \去掉isam表類型支持 現在很少用了 isam表是一種依賴平臺的表 (5.0以前)
--without-innodb \去掉innodb表支持 innodb是一種支持事務處理的表,適合企業級應用 5.0以前)
--with-pthread \強制使用pthread庫(posix線程庫)
--enable-thread-safe-client \以線程方式編譯客戶端
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \以純靜態方式編譯服務端和客戶端
優化編譯:
1. -static 13%
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static
靜態鏈接提高13%性能
2. -pgcc 1%
CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \
-felide-constructors -fno-exceptions -fno-rtti"
如果是Inter處理器,使用pgcc提高 1%性能
3. Unix Socket 7.5%
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
使用unix套接字鏈接提高 7.5%性能,所以在windows下mysql性能肯定不如unix下面
4. --enable-assembler
允許使用匯編模式(優化性能)
如:./configure --prefix=/opt/aimcpro10/mysql-5.1.45 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-path=/opt/aimcpro10/mysql-5.1.45/mysql.sock
--enable-assembler --with-charset=utf8 --with-extra-charsets=gbk --with-plugins=innobase,myisam
安裝完畢後,需要把MySQL 庫加入系統,採用ldconfig 命令來實現:
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig -v | grep libmysqlclient
然後可以看到系統返回:
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
安裝完以後要初始化數據庫,當然你是升級的話不用做這步;
如果重新安裝需要刪除:/var/lib/mysql 中的內容。
/usr/local/mysql/bin/mysql_install_db
建立 mysql 用戶;
/usr/sbin/useradd -M -o -r -d /var/lib/mysql -s /bin/bash -c "MySQL Server" -u 27 mysql
設置權限;
chown -R mysql:mysql /var/lib/mysql
chmod 750 /var/lib/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 750 /usr/local/mysql
添加mysqld服務
ln -sv /usr/local/mysql/bin/* /usr/sbin/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
/******************/
(ubuntu)
cp support-files/mysql.server /var/run/mysqld
chmod 755 /var/run/mysqld
/*****************/
chmod 755 /etc/rc.d/init.d/mysqld
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
好了,至此mysql安裝完畢,可以起動mysql服務
/etc/rc.d/init.d/mysqld start 或 service mysqld start
nohup mysql -uroot -pxxc602 dragon < /home/dragon-2011-02-25 &
掛起後臺執行。
MySQL更改root密碼的方法:
第一種︰
shell>
mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD(’new_password’) WHERE user=’root’; mysql> FLUSH PRIVILEGES;
第二種︰使用 set password 語法
shell> mysql -u root mysql mysql> SET PASSWORD FOR root=PASSWORD(’new_password’);
第三種︰使用 mysqladmin命令
shell>mysqladmin -u root password new_password
MYSQL導入導出:
導入MYSQL的腳本:
nohup mysql -uroot -pxxc602 dragon < /home/dragon-2011-02-25 > myout.file 2>&1 &.
備份MSYQL的腳本:
/usr/sbin/mysqldump dragon -uzycg -pCassandra100017 --skip-opt | gzip > /home/zycg/data/DB_bk/dragon-`date +%F`.gz
忘記Mysql的root密碼,處理方法:
1 sudo killall -TERM mysqld
2 sudo mysqld_safe --skip-grant-tables &
3 不需密碼進入mysql
mysql> update user set password = password('new_password') where user = 'root'(password 可以爲null);
mysql> flush privileges;
4 重新殺Mysql,用正常方法啓動Mysql
新建用戶、爲用戶授權、刪除用戶、修改指定用戶密碼。
首先要聲明一下:一般情況下,修改MySQL密碼,授權,是需要有mysql裏的root權限的。
注:本操作是在WIN命令提示符下,phpMyAdmin同樣適用。
用戶:phplamp 用戶數據庫:phplampDB
1.新建用戶。
//登錄MYSQL
@>mysql -u root -p
@>密碼
//創建用戶
mysql> insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234"));
//刷新系統權限表
mysql>flush privileges;
這樣就創建了一個名爲:phplamp 密碼爲:1234 的用戶。
然後登錄一下。
mysql>exit;
@>mysql -u phplamp -p
@>輸入密碼
mysql>登錄成功
2.爲用戶授權。
//登錄MYSQL(有ROOT權限)。我裏我以ROOT身份登錄.
@>mysql -u root -p
@>密碼
//首先爲用戶創建一個數據庫(phplampDB)
mysql>create database phplampDB;
//授權phplamp用戶擁有phplamp數據庫的所有權限。
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統權限表
mysql>flush privileges;
mysql>其它操作
/*
如果想指定部分權限給一用戶,可以這樣來寫:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統權限表。
mysql>flush privileges;
*/
3.刪除用戶。
@>mysql -u root -p
@>密碼
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數據庫
mysql>drop database phplampDB;
4.修改指定用戶密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="phplamp" and Host="localhost";
mysql>flush privileges;
給root用戶 遠程訪問192.168.0.82的權限。
mysql> grant all privileges on dragon.* to root@'192.168.0.82'identified by 'xxc602';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
grant all privileges on *.* to zycg@'192.168.0.%'identified by 'Cassandra100017';(內網地址)
grant all privileges on dragon.* to root@'%'identified by 'xxc602'; 所有帳號授權。
查看MYSQL表記錄的多少:
select table_name,data_length from information_schema.tables;
SQL code
遠程連接問題,大家可以參考:
1、MYSQL服務器上:
2、比如: C:\>mysql-uroot-p Enter password:******Welcometo the MySQL monitor. Commandsend with ;
3、or \g. Your MySQL connection idis 2
4、Server version:5.1.22-rc-community-log MySQL Community Server (GPL)
5、Type'help;' or '\h' for help. Type'\c' to clear the buffer.
6、mysql> grant all privileges on *.* to 'yourname'@'%' identifiedby 'youpasswd'; Query OK,0 rows affected (0.05 sec)
7、mysql> flushprivileges;
8、Query OK,0 rows affected (0.06 sec)
9、mysql> exitBye
10、 開啓3306的方法:
11、 http://www.google.cn/search?hl=zh-CN&q=%E5%BC%80%E5%90%AF3306&meta=2、這裏假設用SQLYog連接MYSQL服務器。
12、客戶端機器上: HOST ADDRESS:服務端IP地址USER NAME:yourname PASSWORD:yourpasswd PORTS:3306DATABASES:可以留空。