[glibc方式]linux本地安装配置mysql server

下载的是mysql-glibc压缩包


前置配置
  • tar xvf 解压 mysql-linux-glibc-x86_64.tar.xz 至某个文件夹,如 /home/user/my/mysql
  • 创建mysql用户:adduser mysql
  • 将mysql所在安装目录持有者改为 mysql :chown -R mysql:mysql /home/user/my/mysql
  • 赋予权限 : chmod -R 775 /home/user/my/mysql
  • 创建配置文件并编辑自定义参数:touch /etc/my.cnf

[mysql]
#auto-rehash是自动补全的意思
auto-rehash

#默认连接端口                 
port = 3306

#用于本地连接的socket套接字
socket = /tmp/mysqlx.sock

#编码
default-character-set = utf8mb4

[mysqld] 
#skip-name-resolve 

# 指定默认编码格式
character-set-server=utf8

# 设置3306端口
port = 3306  
socket=/tmp/mysqlx.sock

# 设置mysql的安装目录 
basedir=/home/user/my/mysql/mysql-linux-glibc-x86_64

# 指定pid文件
pid-file=/home/user/my/mysql/pid/3306/mysql.pid

# 设置mysql数据库的数据的存放目录 
datadir=/home/user/my/mysql/data

# 指定错误日志
log-error=/home/user/my/mysql/log/err.log

# 允许最大连接数 
max_connections=200

# 服务端使用的字符集默认为8比特编码的拉丁字符集 
character-set-server=utf8 

# 创建新表时将使用的默认存储引擎 
default-storage-engine=INNODB 
#lower_case_table_name=1 
max_allowed_packet=16M


  • 增加系统变量:nano /etc/profile

把以下内容粘贴在末尾:



# mysql
MYSQL_HOME=/home/user/my/mysql/mysql-linux-glibc-x86_64
PATH=$PATH:$MYSQL_HOME/bin
export PATH MYSQL_HOME

source /etc/profile ,即时生效


初始化and启动and登录

  • 初始化,进入安装路径bin目录,执行:./mysqld --initialize --user=mysql

    如果报缺少 libaio 依赖错误,便安装它 :yum install libaio,
    ubuntu 一脉的发行版得如此安装:sudo apt-get install libaio1

  • 根据my.cnf中的错误日志文件路径,去查看日志内容,得到初始的临时密码

[Server] A temporary password is generated for root@localhost: 9Pdvi0ifts^c

  • 启动并登录

    进入support-fils目录,执行: sudo sudo ./mysql.server start 或者 sudo ./mysql.server start --user=mysql

(也还有另一种本地启动方法:./bin/mysqld_safe,此方法是./mysql.server start的底层脚本方式)

在新窗口,输入:mysql -uroot -p,然后提示输入密码,把初始密码输入进去,便可看到:


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20

Copyright (c) 2000, 2020, 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.

success.


  • 改密码: alter user 'root'@'localhost' identified by 'newPassword';
  • 查看用户host地址: select user,host from mysql.user;

启动与停止之命令

mysql-start:


#!/bin/sh
sudo /home/user/my/mysql/8.0.20/mysql-linux-glibc-x86_64/support-files/mysql.server start --user=mysql

mysql-stop:


#!/bin/sh
sudo /home/user/my/mysql/8.0.20/mysql-linux-glibc-x86_64/support-files/mysql.server stop --user=mysql

你可能感兴趣的:(mysql,linux)