ubuntu16.04安装mysql5.7.24

mysql 同时被 2 个专栏收录
11 篇文章 0 订阅
17 篇文章 0 订阅

同步个人博客:ubuntu16.04安装mysql5.7.24

参考本人CSDN博客上写的文章: 64位centos6.7安装mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

1. 下载安装包及安装相关依赖

官网: http://dev.mysql.com/downloads/mysql/

mysql搜狐镜像站:
http://mirrors.sohu.com/mysql/

mkdir ~/soft/
cd ~/soft/
wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

安装mysql前先安装所需依赖:

sudo apt-get install libmysqlclient-dev python3-dev

2. 创建mysql的用户组/用户, data目录及其用户目录

sudo groupdel mysql
sudo userdel mysql
sudo groupadd mysql
sudo useradd -g mysql -d /home/mysql -m mysql
sudo mkdir -p /home/mysql/data

3. 解压安装包并将解压包里的内容拷贝到mysql的安装目录/home/mysql

tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
cd ~/soft/mysql-5.7.24-linux-glibc2.12-x86_64/
sudo mv * /home/mysql

4. 初始化mysql数据库

cd /home/mysql
./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize

在上面命令执行完后, 牢记最后一行打印信息的随机密码, 如上**mjT,#x_5sW, 下面我们修改密码时需要用到。

5. 编辑mysql服务文件

vim /home/mysql/support-files/mysql.server
#########修改basedir和datadir==========
basedir=/home/mysql
datadir=/home/mysql/data
############end############

6. 创建软链接

sudo ln -s /home/mysql/bin/mysql /usr/bin/mysql

7. 创建配置文件

若存在/etc/my.cnf, 将默认生成的my.cnf备份:

sudo mv /etc/my.cnf /etc/my.cnf.bak

创建配置文件:

sudo vim /etc/my.cnf

/etc/my.cnf配置文件内容如下:

[mysqld]

basedir = /home/mysql
datadir = /home/mysql/data

character_set_server=utf8
init_connect='SET NAMES utf8'
socket=/home/mysql/mysql.sock

[client]
default-character-set=utf8
socket=/home/mysql/mysql.sock

8. 配置mysql服务开机自动启动

sudo cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld
sudo chmod 755 /etc/init.d/mysqld
systemctl enable mysqld
systemctl start mysqld
sudo lsof -i:3306

9. 修改初始化时mysql用户root的密码

通过mysqladmin命令来修改root密码, 原密码为mysqld --initialize时牢记下的随机密码, 并检测mysql编码集是否为utf-8, 如下:

cd /home/mysql
$ ./bin/mysqladmin -u root -p password
Enter password: 
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \s
--------------
mysql Ver 14.14 Distrib 5.7.24, for linux-glibc2.12 (x86_64) using EditLine wrapper

Connection id: 3
Current database: 
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 5.7.24 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 3 min 18 sec

Threads: 1 Questions: 9 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 99 Queries per second avg: 0.045
--------------

mysql> show variables like "%char%";
+--------------------------+-----------------------------+
| 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 | /home/mysql/share/charsets/ |
+--------------------------+-----------------------------+
8 rows in set (0.00 sec)

mysql> 

10. mysql相关命令

p.s. 非root用户在执行以下命令前要加sudo

启动mysql服务: systemctl start mysqld

停止mysql服务: systemctl stop mysqld

重启mysql服务: systemctl restart mysqld

查看mysql服务状态: systemctl status mysqld or lsof -i:3306

  • 1
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 程序猿惹谁了 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值