deepin普通用户安装mysql数据库

古起运
2023-12-01

1、解压缩文件

shiguojian@shiguojian-PC:~$ tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz 
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.36-linux-glibc2.12-x86_64/bin/mysql

2、重命名为mysql

shiguojian@shiguojian-PC:~$ mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql

3、进入到mysql目录

shiguojian@shiguojian-PC:~$ cd mysql
shiguojian@shiguojian-PC:~/mysql$ vi my.cnf

4、将以下内容复制过去

[mysqld]
#端口号
port = 3306
#mysql-5.7.36文件的路径
basedir=/home/shiguojian/mysql
#mysql-5.7.36数据路径
datadir=/home/shiguojian/mysql/data
log-error=/home/shiguojian/mysql/data/mysql.err
pid-file=/home/shiguojian/mysql/mysql.pid
socket=/home/shiguojian/mysql/mysql.sock
#最大连接数
max_connections=600
#编码
character-set-server=utf8
#skip-grant-tables
default-storage-engine=INNODB
#不区分大小写
lower_case_table_names=1
#绑定ipv4
bind-address=0.0.0.0
#设置传输包限制,默认1M
max_allowed_packet=64M
#设置缓冲池大小:
innodb_buffer_pool_size=1024M
#设置隔离级别
transaction-isolation=read-committed
#设置时区
default-time-zone='+8:00'
#设置密码验证默认加密方式
#default-authentication-plugin=mysql_native_password
explicit_defaults_for_timestamp=true
[mysql]
#编码

5、保存退出
6、进入到MySQL目录,新建文件夹data

shiguojian@shiguojian-PC:~/mysql$ mkdir data

7、开始安装MySQL

shiguojian@shiguojian-PC:~/mysql$ bin/mysqld --defaults-file=/home/shiguojian/mysql/my.cnf --initialize --user=shiguojian --based
ir=/home/shiguojian/mysql --datadir=/home/shiguojian/mysql/data

#–defaults-file指定配置文件
#–initialize自动生成带有随机的root密码
8、临时密码保存位置在/home/shiguojian/mysql/data/mysql.err

shiguojian@shiguojian-PC:~/mysql/data$ cat mysql.err 
2022-04-12T11:58:29.666817Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-12T11:58:30.182007Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-12T11:58:30.415319Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this serve
r has been started. Generating a new UUID: dec71548-ba57-11ec-987c-00155d0a1402.2022-04-12T11:58:30.470733Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-04-12T11:58:32.787324Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-04-12T11:58:32.787335Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-04-12T11:58:32.787711Z 0 [Warning] CA certificate ca.pem is self signed.
2022-04-12T11:58:32.942397Z 1 [Note] A temporary password is generated for root@localhost: dAFdiZv_J0Vq

9、启动MySQL

shiguojian@shiguojian-PC:~/mysql$ bin/mysqld_safe --defaults-file=/home/shiguojian/mysql/my.cnf --user=shiguojian &
[1] 14780
shiguojian@shiguojian-PC:~/mysql$ 2022-04-12T12:33:07.855324Z mysqld_safe Logging to '/home/shiguojian/mysql/data/mysql.err'.
2022-04-12T12:33:07.889244Z mysqld_safe Starting mysqld daemon with databases from /home/shiguojian/mysql/data

停止MySQL

shiguojian@shiguojian-PC:~/mysql$ bin/mysqladmin shutdown -uroot -p -S /home/shiguojian/mysql/mysql.sock
Enter password: 

10、登陆MySQL控制台

shiguojian@shiguojian-PC:~/mysql$ bin/mysql -uroot -pdAFdiZv_J0Vq -S /home/shiguojian/mysql/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.36

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

11、修改root密码并配置远程链接

mysql> set password=password('one123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'one123456t';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

查看字符集、数据殷勤、大小写敏感等

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/shiguojian/mysql/share/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.01 sec)

mysql> show variables like '%engine%';
+----------------------------------+--------+
| Variable_name                    | Value  |
+----------------------------------+--------+
| default_storage_engine           | InnoDB |
| default_tmp_storage_engine       | InnoDB |
| disabled_storage_engines         |        |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+
4 rows in set (0.00 sec)

mysql> show variables like '%lower%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 1     |
+------------------------+-------+
2 rows in set (0.01 sec)

mysql> 

 类似资料: