mysql安装

linux

下载 https://downloads.mysql.com/archives/community/

Compressed TAR Archive, Minimal Install 不包含调试和测试工具

1
2
xz -d mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
tar -xvf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar

用户组

1
2
3
4
5
6
7
8
9
10
11
#添加组
sudo groupadd mysql
sudo useradd -r -M -s /sbin/nologin -g mysql mysql -d /opt/mysql

# cs 或 ${USER}
sudo chown mysql:${USER} -R /opt/mysql/*

cs@debian:~/data/software$ cat /etc/group | grep mysql
mysql:x:512:cs
cs@debian:~/data/software$ cat /etc/passwd | grep mysql
mysql:x:512:512::/home/mysql:/sbin/nologin

初始化数据库

1
$ sudo /opt/mysql/bin/mysqld  --initialize --user=mysql --console

……

—-2022-01-30T00:14:24.872326+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: bDB,fVSmt2/U

修改配置

默认/etc/my.cnf

1
2
3
4
url=/opt/mysql
sed -n "/^basedir=/s#=#==$url#"p ./mysql.server
sed -n "/^datadir=/s#=#=$url/data#"p ./mysql.server
sed -n "s#conf=.*#conf=$url/my.cnf#"p ./mysql.server

开机启动

1
2
3
4
5
sudo cp /opt/mysql/support-files/mysql.server  /etc/init.d/mysql
设置为开机自动运行
sudo update-rc.d mysql defaults
设置为取消开机自动运行
sudo update-rc.d -f mysql remove

密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
##### 临时密码登录,执行语句提示 You must reset your password using ALTER USER statement before executing this statement.
--- alter user user() identified by "123456"; ##密码字符串双引号

---低于版本8---SET PASSWORD FOR root@localhost = '123456';
---版本8以上---ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

##用户密码过期时间250天
ALTER USER ‘cs’@‘localhost' PASSWORD EXPIRE INTERVAL 250 DAY;
###禁用过期 --恢复默认策略 PASSWORD EXPIRE DEFAULT----
ALTER USER 'cs'@'localhost' PASSWORD EXPIRE NEVER;

###密码过期的策略
show variables like 'default_password_lifetime';
---设置密码永不过期,需要把default_password_lifetime修改为 0
---set global default_password_lifetime = 0;

CREATE USER 'cs'@'localhost' IDENTIFIED BY '123456';


###修改执行生效语句
flush privileges;

win

下载地址:http://dev.mysql.com/downloads/mysql/

管理员权限运行cmd

1
E:\MySQL\MySQL Server 5.7\bin>mysqld install MySQL --defaults-file="E:\MySQL\MySQL Server 5.7\my.ini"

install/Remove of the Service Denied!

1
bin>mysqld --initialize --user=mysql --console

启动服务

1
net start MySQL

删除

1
sc delete MySQL

other

Permission denied

检查目录所属用户mysql

rm /tmp/mysql*

1
2
3
4
5
6
❯ ls -l /tmp/mysql*
-rw-r----- 1 mysql mysql 6 6月 4 21:08 /tmp/mysqld.pid
srwxrwxrwx 1 mysql mysql 0 6月 4 21:08 /tmp/mysql.sock
-rw------- 1 mysql mysql 6 6月 4 21:08 /tmp/mysql.sock.lock
srwxrwxrwx 1 mysql mysql 0 6月 4 21:08 /tmp/mysqlx.sock
-rw------- 1 mysql mysql 6 6月 4 21:08 /tmp/mysqlx.sock.lock

端口

1
2
/opt/mysql/bin/mysqld  --initialize-insecure --user=mysql  --lower-case-table-names=1
/opt/mysql/bin/mysqld --user=mysql &

╰─❯ 2023-06-04T11:50:10.086155Z 0 [System] [MY-010116] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.32) starting as process 5008
2023-06-04T11:50:10.089112Z 0 [Warning] [MY-010122] [Server] One can only use the –user switch if running as root
2023-06-04T11:50:10.094189Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-06-04T11:50:10.195060Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-06-04T11:50:10.385679Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-06-04T11:50:10.385746Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-06-04T11:50:10.386292Z 0 [ERROR] [MY-010262] [Server] Can’t start server: Bind on TCP/IP port: Address already in use
2023-06-04T11:50:10.386343Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3306 ?
2023-06-04T11:50:10.386383Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-06-04T11:50:11.974477Z 0 [System] [MY-010910] [Server] /opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.

1
sudo netstat -apn | grep 3306
点击打赏
文章目录
  1. 1. linux
    1. 1.1. 用户组
    2. 1.2. 初始化数据库
    3. 1.3. 修改配置
    4. 1.4. 开机启动
    5. 1.5. 密码
  2. 2. win
  3. 3. other
    1. 3.1. Permission denied
    2. 3.2. 端口
载入天数...载入时分秒... ,