ubuntu离线安装mysql5.7

1,建立mysql 账户和组

sudo -i 作为root进行操作

[root@CDH-141 ~]# groupadd mysql # 创建mysql用户组
[root@CDH-141 ~]# useradd -g mysql mysql   # 创建一个用户名为mysql的用户,并加入mysql用户组
[root@CDH-141 ~]# passwd mysql   # 制定password 为111111  (用户mysql的密码)

2,移动文件

# 解压mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz
[root@CDH-141 local]# tar -zxvf mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz
[root@CDH-141 local]# mv mysql-5.7.43-linux-glibc2.12-x86_64  /usr/local/mysql

3,# 更改所属的组和用户
cd /usr/local

[root@CDH-141 local]# chown -R mysql mysql/

[root@CDH-141 local]# chgrp -R mysql mysql/

[root@CDH-141 local]# cd mysql/ [root@CDH-141 mysql]# mkdir data

[root@CDH-141 mysql]# chown -R mysql:mysql data

mkdir /var/lib/mysql

chown -R mysql /var/lib/mysql

chgrp -R mysql /var/lib/mysql

4,在/etc下创建my.cnf文件

# 编辑my.cnf
[root@CDH-141 mysql]# vim /etc/my.cnf

[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port  
port = 3323 #默认是3306
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
#忽略数据库表名的大小写
lower_case_table_names=1
#最大请求包
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysql.server]
user=mysql #用户不是mysql时,更改此处
basedir=/usr/local/mysql

5,安装mysql,设置mysql服务

# 安装mysql
[root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@CDH-141 mysql]# chown 777 /etc/my.cnf
[root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld

6,启动mysql服务

# 启动mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld start/restart/stop/status
或者
[root@CDH-141 mysql]# service mysqld start/stop/restart/status

7,将mysql命令加入环境变量path中

vim ~/.bashrc

export PATH=$PATH:/usr/local/mysql/bin
export LD_LIBRARY_PATH=/usr/local/mysql/lib

保存退出

source ~/.bashrc

8, 获得mysql初始密码,运行mysql尝试登录

cat /root/.mysql_secret  

mysql -pZb3JrNaTUg-a 如报错:

mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

apt install -y libncurses*

9,修改密码

 set PASSWORD = PASSWORD('123456');

10,添加远程访问权限

# 添加远程访问权限
mysql> use mysql

# 修改root用户可以远程登录:
mysql> update user set host='%' where user='root'; 
flush privileges;
或者
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root用户密码' WITH GRANT OPTION;
无需flush privileges;

mysql> select host,user from user;

远程账号登录时,此时需要指定-P3323,因为之前我们创建的my.cnf文件中的端口为3323,如果改成默认的3306端口,并重启mysql服务后,可以不追加-P参数

mysql -uroot -proot用户密码 -h你的主机 -P3323

从mysql官网上下载mysql-server_5.7.21-1ubuntu14.04_amd64.deb-bundle.tar,然后进行离线安装,解压该安装包,会出现11个依赖包,按照顺序依次使用sudo dpkg -i 进行安装,中间会报错,显示缺少相应的依赖,具体如下: *******@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-client. (Reading database ... 208518 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-client (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-client: mysql-community-client depends on libaio1 (>= 0.3.93); however: Package libaio1 is not installed. dpkg: error processing package mysql-community-client (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Errors were encountered while processing: mysql-community-client 和 ********@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-server. (Reading database ... 208598 files and directories currently installed.) Preparing to unpack mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-server (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-server: mysql-community-server depends on libmecab2 (>= 0.996-1.1); however: Package libmecab2 is not installed. dpkg: error processing package mysql-community-server (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... ureadahead will be reprofiled on next reboot Errors were encountered while processing: mysql-community-server 附上依赖包安装顺序: 1.mysql-common_5.7.21-1ubuntu14.04_amd64.deb 2.libmysqlclient20_5.7.21-1ubuntu14.04_amd64.deb 3.libmysqlclient-dev_5.7.21-1ubuntu14.04_amd64.deb 4.libmysqld-dev_5.7.21-1ubuntu14.04_amd64.deb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值