第一次接触服务器版Linux,也是第一次用命令行安装二进制mysql,两天一晚上,比较痛苦。留作备忘!
首先,下载二进制版本的mysql包: http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
准备工做:
一、下载mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
二、将软件拷贝到目的服务器/work/software目录下(使用FlashFXPPortable工具,传输模式设置为二进制)
三、在/work/software目录下输入如下命令,赋予可执行权限
chmod 777 mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
安装步骤
使用root帐户登陆服务器
一、解压tar.gz
tar –xzf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
二、重命名解压的文件夹
mv mysql-5.6.10-linux-glibc2.5-x86_64 mysql
三、将mysql文件夹移动到/usr/local目录下
sudo mv mysql /usr/local
四、进入mysql目录
cd /usr/local/mysql
userdel -r mysql
groupdel mysql
五、增长mysql用户组
sudo groupadd mysql
六、增长mysql用户
sudo useradd -r -g mysql mysql
七、将mysql文件夹own及grp变动为mysql
sudo chown -R mysql .
sudo chgrp -R mysql .
八、执行mysql安装脚本
sudo scripts/mysql_install_db --user=mysql
(若未安装libaio包,会有一个报错提示,安装libaio-dev后,再运行脚本便可)
sudo apt-get install libaio-dev
九、将目录权限变动回来,仅保留data目录为mysql用户
sudo chown -R root .
sudo chown -R mysql data
十、将mysql配置文件拷贝到etc目录(全局配置)
注意:5.6版本的默认配置文件名称由原先的my-medium变动为了my-default。
sudo cp support-files/my-default.cnf /etc/my.cnf
十一、启动mysql
sudo bin/mysqld_safe --user=mysql &
十二、初始化mysql root用户密码
sudo bin/mysqladmin -u root password '密码文字'
1三、复制mysql.server脚本到/etc/init.d(初始化服务,有些人喜欢改为mysqld,在这里改就能够)
sudo cp support-files/mysql.server /etc/init.d/mysql.server
sudo cp support-files/mysql.server /etc/init.d/mysqld
1四、查看mysql运行状态
sudo service mysql.server status
若是运行正常,会显示 MySQL running。
若是显示 not running,应该是前面没有启动服务,可直接用service mysql.server start启动
sudo service mysql.server [status|start|stop]
1五、让mysql开机启动[defaults],取消开机启动[remove]
ubuntu sudo update-rc.d -f mysql.server defaults [remove]
centos:
方法二:在mysql5目录下找到support-files目录将其中的mysql.server复制修改成/etc/init.d/mysqld
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
chkconfig --level 35 mysqld on
1六、将mysql/bin/mysql命令加入到用户命令中,或将mysql/bin目录加入path
加入用户命令:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
加入环境变量:
export PATH=$PATH:/usr/local/mysql/bin
1七、容许root用户远程登陆
1>进入mysql: mysql –u root –p
2>改变数据库: use mysql;
3>从任意主机登陆: grant all privileges on *.* to root@"%" identified by "密码文字" with grant option;
4>从指定主机登陆: grant all privileges on *.* to root@"10.51.14.131" identified by "passw0rd" with grant option;
grant all privileges on *.* to root@"10.51.14.131" identified by "archermind" with grant option;
grant all privileges on *.* to root@"27.17.36.150" identified by "archermind1!2@3#4$" with grant option;
grant all privileges on *.* to root@"211.166.9.218" identified by "archermind1!2@3#4$" with grant option;
grant all privileges on *.* to root@"10.52.12.89" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.52.12.36" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.51.14.31" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.51.14.42" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.51.14.131" identified by "archermind" with grant option;
5>受权生效: flush privileges;
6>查看host为%受权是否添加: select * from user;
1八、找个客户端试试
mysql