1、下载mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
2、解压到安装目录
#解压
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
#复制解压后的mysql目录
cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
3、添加用户组和用户
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -g mysql mysql
4、安装
1)、cd /usr/local/mysql/ mkdir ./data/mysql
2)、chown -R mysql:mysql ./
3)、./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql (错误1)
4)、cp support-files/mysql.server /etc/init.d/mysqld (错误2)
5)、chmod 755 /etc/init.d/mysqld
6)、cp support-files/my-default.cnf /etc/my.cnf
7)、 #修改启动脚本
vi /etc/init.d/mysqld
8)、#修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
9)、#启动服务
service mysqld start
10)、#测试连接
./mysql/bin/mysql -uroot
11)、#加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql//bin source /etc/profile
说明:
#启动mysql service mysqld start
#关闭mysql service mysqld stop
#查看运行状态 service mysqld status
备注:安装过程遇到错误莫要慌张
错误1、FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
解决方法 :安装autoconf库 命令:yum-y install autoconf
错误2、Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
当我们使用“mysql_install_db”安装MySQL时,需要libaio包,现将不同Linux系统安装该包的方式总结如下:
1、对于Redhat/CentOS系统用如下安装方式:[root@dbhost01~]# yum install libaio
2、对Debian系统用如下安装方式:root@dbhost01:~# apt-get install libaio1
远程访问注意事项:
远程访问时需要密码安装全程没有设置过密码就需要修改密码了
停止msql服务
ps -ef|grep mysql
杀死进程 kill -9 8389
2.修改MySQL的登录设置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。
3.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登录并修改MySQL的root密码
# ./mysql/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> USE mysql ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
5.将MySQL的登录设置修改回来
# vi /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vi。
6.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
连接时,报1130错误,是由于没有给远程连接的用户权限问题
解决1:更改 ‘mysql’数据库‘user’表‘host’项,从‘localhost’改成‘%’。
use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
解决2:直接授权
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;
云服务器端口没开放问题