[Exchange and share] deepin v23安装mysql数据库
Tofloor
poster avatar
HelloWorld!
deepin
2024-04-12 23:40
Author

最近准备把开发环境换到deepinv23,这里记录一下deepinv23安装mysql的过程

一:下载mysql

Mysql 下载, tar.gz 格式

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

image.png

二:解压到/usr/local/mysql

image.png


root@mhc-PC:/usr/local/mysql# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
# 解压
root@mhc-PC:/usr/local/mysql# mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql-5.7.18
# 重命名为mysql

三:初始化mysql

  • 新建/etc/my.cnf,其中所有的路径根据自己电脑修改,编辑为
    mhc@mhc-PC:~$ sudo vim /etc/my.cnf
    # 在/etc下新建my.cnf
    # 编辑其内容为
    [client]
    socket=/usr/local/mysql/mysql-5.7.18/mysql.sock
    port=3306
    
    [mysql]
    default-character-set=utf8
    
    [mysqld]
    basedir=/usr/local/mysql/mysql-5.7.18
    datadir=/usr/local/mysql/mysql-5.7.18/data
    port=3306
    pid-file=/usr/local/mysql/mysql-5.7.18/mysqld.pid
    socket=/usr/local/mysql/mysql-5.7.18/mysql.sock
    character-set-server=utf8
    default-storage-engine=INNODB
    explicit_defaults_for_timestamp=true
    server-id=1
    
    
    

image.png

  • 在/usr/local/mysql/mysql-5.7.18/bin 目录执行初始化命令
    mhc@mhc-PC:/usr/local/mysql$ sudo chown -R mhc ./mysql-5.7.18
    # 修改权限
    mhc@mhc-PC:/usr/local/mysql/mysql-5.7.18/bin$ sudo ./mysqld --user=root --basedir=/usr/local/mysql/mysql-5.7.18 --datadir=/usr/local/mysql/mysql-5.7.18/data --initialize
    2024-04-12T05:11:09.657244Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2024-04-12T05:11:10.203602Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2024-04-12T05:11:10.410913Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 135d9db6-f88b-11ee-b0f9-2c56dcb5637f.
    2024-04-12T05:11:10.470114Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2024-04-12T05:11:10.471334Z 1 [Note] A temporary password is generated for root@localhost: #)Rghy%B)4tn
    # 初始化 #)Rghy%B)4tn为默认密码,需要复制下来
    
    

四:启动mysql

mhc@mhc-PC:/usr/local/mysql/mysql-5.7.18$ cd ./support-files/
# 打开support-files 
root@mhc-PC:/usr/local/mysql/mysql-5.7.18# cp ./support-files/mysql.server  /etc/init.d/mysqld
# 复制mysql.server到/etc/init.d/
mhc@mhc-PC:/usr/local/mysql/mysql-5.7.18/support-files$ ./mysql.server start
Starting MySQL
...
# 执行
mhc@mhc-PC:/usr/local/mysql/mysql-5.7.18$ mysql -u root -p;
Enter password: 
# 初始密码在初始化后生成
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> 
# 启动完成
mysql> alter user 'root'@'localhost' IDENTIFIED BY 'xxx';
Query OK, 0 rows affected (0.00 sec)
# 设置新密码xxx

Reply Favorite View the author
All Replies
👀偷偷观察
deepin
2024-04-12 23:52
#1

docker

Reply View the author
raspbian
deepin
2024-04-13 05:48
#2

我选择容器化

Reply View the author
andot
deepin
2024-04-20 12:38
#3
docker pull mysql:5.7

docker run -d --name mysql -e MYSQL\_ROOT\_PASSWORD=root -p 3306:3306 -v /opt/mysql/logs:/var/log/mysql -v /opt/mysql/data:/var/lib/mysql -v /opt/mysql/conf:/etc/mysql/conf.d --restart=always  mysql:5.7

docker方式很方便,两行命令就搞定。

Reply View the author