Linux 安装 MySql

1. 下载所需安装软件

mkdir -p /root/soft
cd /root/soft
wget -c http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
wget -c http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz/from/http://mysql.cs.pu.edu.tw/


2. 安装cmake和bison

cd /root/soft
tar -zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./bootstrap
make && make install
cd ../

cd /root/soft
tar -zxvf bison-2.5.tar.gz
cd bison-2.5
./configure
make && make install
cd ../

或者 yum -y install cmake
或者 yum -y install bison


3. 编译安装 MySQL 5.5.15

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cd /root/soft
tar -zxvf mysql-5.5.15.tar.gz
cd mysql-5.5.15/
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DWITH_DEBUG=0
-DMYSQL_USER=mysql
make
make install
chown -R mysql:mysql /usr/local/mysql
cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
sed -i '/\[mysqld\]/a\datadir = /usr/local/mysql/data' /etc/my.cnf
chown -R mysql:mysql /usr/local/mysql/data
ln /usr/local/mysql/bin/mysqldump /usr/local/bin
ln /usr/local/mysql/bin/mysqladmin /usr/local/bin
ln /usr/local/mysql/bin/mysql /usr/local/bin


4. 启动和关闭

service mysqld start
service mysqld stop
service mysqld restart


5. mysql启动报错:Starting MySQL.The server quit without updating PID file

解决办法:配置/etc/my.cnf ,在[mysqld]下面加上:datadir = /usr/local/mysql/data ;
          先 chown -R mysql:mysql /usr/local/mysql/data 然后杀掉mysql进程,在启动musql


6. 修改root密码

use mysql ;
update user set password=PASSWORD("1") where user='root';
FLUSH PRIVILEGES;

重启mysql就OK了


7. 如果需要让特定的用户从给定域(例如koko.com)的所有计算机上访问 MySQL 服务器,
    你可以执行在账户名的 host 部分使用了通配符“%” 的 GRANT 语句
    update user set Host='%.koko.com' where User='root';
    一般:
    update user set Host='%' where User='root';


8. 导入mysql数据库,直接在命令行输入以下:
   mysql -h localhost -u root -p loupan < f:\ko\loupan.sql
   然后输入密码,就OK了   


9. 导出mysql数据库,直接在命令行输入以下:
   mysqldump -h localhost -u root -p loupan > f:\ko\loupan.sql
   然后输入密码,就OK了


--- 至此 MySql 已经安装好了!

你可能感兴趣的:(mysql,linux,下载,安装软件,cd)