鉴于网上众多的安装教程,实际操作过程中遇到不少坑,最主要的是因为在不能连接外网的服务器进行安装,特地整理了此文档,已做分享,有不足之处请可提出,后续继续修正。
以下是本人亲自操作,一步一步记录下来
Mysql5.16离线安装
首先到官网下载数据库安装包
官网下载地址:
http://dev.mysql.com/downloads/
http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar
下载依赖库 libaio,libmecab2
http://us.archive.ubuntu.com/ubuntu/pool/main/liba/libaio/
http://packages.ubuntu.com/trusty/amd64/libmecab2/download
1、资源准备
将下载好的安装包,统一放进指定目录 /opt/tools
mysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar
libaio1_0.3.110-3_amd64.deb
libmecab2_0.996-1.1_amd64.deb
2、安装依赖包、解压mysql安装包
安装前最好对源进行一次更新(不能更新就算了)
sudo apt-get update
2.1 安装依赖包
sudo dpkg -ilibaio1_0.3.110-3_amd64.deb
sudo dpkg -ilibmecab2_0.996-1.1_amd64.deb
2.2 解压mysql 安装包
sudo chmod +xmysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar
tar -xfmysql-server_5.7.16-1ubuntu14.04_amd64.deb-bundle.tar
3、安装MYSQL服务
通过解压之后会出现以下的文件列表
libmysqlclient20_5.7.16-1ubuntu14.04_amd64.deb
libmysqlclient-dev_5.7.16-1ubuntu14.04_amd64.deb
libmysqld-dev_5.7.16-1ubuntu14.04_amd64.deb
mysql-client_5.7.16-1ubuntu14.04_amd64.deb
mysql-common_5.7.16-1ubuntu14.04_amd64.deb
mysql-community_5.7.16-1ubuntu14.04_amd64.changes
mysql-community-client_5.7.16-1ubuntu14.04_amd64.deb
mysql-community-server_5.7.16-1ubuntu14.04_amd64.deb
mysql-community-source_5.7.16-1ubuntu14.04_amd64.deb
mysql-community-test_5.7.16-1ubuntu14.04_amd64.deb
mysql-server_5.7.16-1ubuntu14.04_amd64.deb
mysql-testsuite_5.7.16-1ubuntu14.04_amd64.deb
分别进行安装,在此需要特别注意安装顺序,负责安装会出现错误
sudo dpkg -imysql-common_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg-preconfiguremysql-community-server_5.7.16-1ubuntu14.04_amd64.deb
安装过程中会弹出界面提示输入密码,请记录好自己的root密码
继续...
sudo dpkg -ilibmysqlclient20_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -ilibmysqlclient-dev_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -ilibmysqld-dev_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -imysql-community-client_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -imysql-client_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -imysql-common_5.7.16-1ubuntu14.04_amd64.deb
sudo dpkg -imysql-community-server_5.7.16-1ubuntu14.04_amd64.deb
--如果安装这步出现异常,请移步下面解决
sudo dpkg -imysql-server_5.7.16-1ubuntu14.04_amd64.deb
这时数据安装完成,并已经自动启动
安装中可能存在的问题
安装mysql-community-server可能出现如下异常
debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable
Selecting previously unselected package libmecab2.
解决办法:
执行语句:fuser -v /var/cache/debconf/config.dat
然后直接kill 掉这个(上面语句查询出来的)进程号
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
解决办法:(这个多半是因为未正常终止某执行语句所致)
执行语句:
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
然后继续安装即可
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
解决办法:
执行语句:sudo dpkg --configure -a
Mysql 基础配置
1、配置远程可以访问
第一步
设置配置文件 /etc/mysql/my.cnf (注意:mysql5.6以上版本,这个参数在 /etc/mysql/mysql.conf.d/mysqld.cnf)
将文件中的bind-address 设置为如下形式
bind-address = 0.0.0.0
第二步(你想myuser使用mypassword从任何主机连接到mysql服务器的话)
使用mysql客户端登录数据(用root账号)语句如下:
mysql -uroot -p你刚刚设定的管理员密码 回车
执行以下语句:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
刷新配置,使其生效
FLUSH PRIVILEGES;
2、设置mysql大小写敏感
直接打开MySQL的 my.ini文件,一般默认在 /etc/mysql/ 目录下
在文件的[mysqld] 下面加入
#设定大小写敏感配置(0:大小写敏感;1:大小写不敏感)
lower_case_table_names=1
--(0:大小写敏感;1:大小写不敏感)最后重启一下MySql服务即可
3、设置默认编码格式为UTF-8
直接打开MySQL的 my.ini文件,一般默认在 /etc/mysql/ 目录下
# my configration
[client]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci
lower_case_table_names=1
验证配置效果:登录mysql数据库 mysql -uroot -p你的db密码,回车,登录后执行如下语句
show variables like 'character%';
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
得到如上效果,说明配置成功!
网友评论