日期:2014-05-16  浏览次数:20665 次

linux下mysql安装及配置.txt
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> tar -zxvf mysql-VERSION.tar.gz (如:mysql-5.0.22)
shell> cd mysql-VERSION(如:cd mysql-5.0.22)
shell> ./configure --prefix=/usr/local/mysql
   --with-extra-charsets=utf8 #添加utf-8字符编码集
   --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cp support-files/mysql.server /etc/init.d/mysqld #copy启动的mysqld文件
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
shell> chown -R root  .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &
shell> cd /
shell> chmod 777 tmp

如果要在任何目录下都可运行mysql,则可执行如下步骤:
shell> cd /usr/local/mysql/bin
shell> cp mysql* /usr/bin


mysql远程连接开启
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改成"%"

mysql -u root -pvmwaremysql
>use mysql;
>update user set host='%' where host='localhost';
>select host, user from user;

2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;



GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.*' IDENTIFIED BY 'wsportal' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.162' IDENTIFIED BY 'adminwangsu' WITH GRANT OPTION;
三、 数据库直接备份到其它机器上
mysqldump -uroot -padminwangsu cdnplatform | mysql -uroot -padminwangsu -h 192.168.18.9 cdnplatform

mysqldump -uroot -pceipportal -h192.168.0.100 wsportal | mysql -uroot -pwangsu wsportal

mysqldump -h 192.168.0.100 -u root -padminwangsu cncportal -R > /home/tomcat/scripts/cncportal.sql
? -h 表示数据库IP;
? -u 表示数据库用户名;
? -p 表示数据库密码(p后面不含空格);
? cncportal 表示数据库名;
? -R 表示导出存储过程以及自定义函数;

数据库恢复
mysqladmin -uroot -proot create 数据库名称
mysql -uroot -proot 数据库名称 < 导入文件.sql
导入中文
mysql -uroot -padminwangsu --default-character-set=utf8 resource < /home/czp/wsResource/deploy/init.sql

mysql -uroot -pceipportal -h192.168.0.100 --default-character-set=utf8 wsportal < d:/ws_customer.sql

UNIX下启动mysql
mysqld_safe --user=mysql &

改变mysql的权限
chmod 777 /tmp

10. 启动服务方法
/usr/local/mysql/bin/mysqld_safe --user=mysql &
或者 usr/local/mysql/share/mysql/mysqld start
11. 停止服务方法
/usr/local/mysql/bin/mysqladmin shutdown

表名不区分大小写
lower_case_table_names=1