ubuntu16.04和win10下安装mysql

ubuntu上安装mysql非常简单只需要几条命令就可以完成。(fa80g)

1. sudo apt-get install mysql-server(过程中会提示设置root用户密码,共两次,一次新建,一次确认)
  
2. sudo apt-get install mysql-client

3. sudo apt-get install libmysqlclient-dev

安装完成之后可以使用如下命令来检查是否安装成功:

sudo netstat -tap | grep mysql

通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。

登陆mysql数据库可以通过如下命令:

mysql -u root -p

-u 表示选择登陆的用户名, -p 表示登陆的用户密码(wang),上面命令输入之后会提示输入密码,此时输入密码就可以登录到mysql。

wang@wang:~$ sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-112 linux-headers-4.4.0-112-generic linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-headers-4.4.0-119
  linux-headers-4.4.0-119-generic linux-headers-4.4.0-121 linux-headers-4.4.0-121-generic linux-headers-4.4.0-124
  linux-headers-4.4.0-124-generic linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-headers-4.4.0-128
  linux-headers-4.4.0-128-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic linux-headers-4.4.0-133
  linux-headers-4.4.0-133-generic linux-headers-4.4.0-134 linux-headers-4.4.0-134-generic linux-headers-4.4.0-137
  linux-headers-4.4.0-137-generic linux-image-4.4.0-112-generic linux-image-4.4.0-116-generic linux-image-4.4.0-119-generic
  linux-image-4.4.0-121-generic linux-image-4.4.0-124-generic linux-image-4.4.0-127-generic linux-image-4.4.0-128-generic
  linux-image-4.4.0-130-generic linux-image-4.4.0-133-generic linux-image-4.4.0-134-generic linux-image-4.4.0-137-generic
  linux-image-extra-4.4.0-112-generic linux-image-extra-4.4.0-116-generic linux-image-extra-4.4.0-119-generic
  linux-image-extra-4.4.0-121-generic linux-image-extra-4.4.0-124-generic linux-image-extra-4.4.0-127-generic
  linux-image-extra-4.4.0-128-generic linux-image-extra-4.4.0-130-generic linux-image-extra-4.4.0-133-generic
  linux-image-extra-4.4.0-134-generic linux-image-extra-4.4.0-137-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libevent-core-2.0-5 libhtml-template-perl mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
  libevent-core-2.0-5 libhtml-template-perl mysql-server mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 5 newly installed, 0 to remove and 366 not upgraded.
Need to get 10.6 MB of archives.
After this operation, 95.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-server-core-5.7 amd64 5.7.24-0ubuntu0.16.04.1 [7,757 kB]
Ign:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libevent-core-2.0-5 amd64 2.0.21-stable-2ubuntu0.16.04.1
Err:3 https://cn.archive.ubuntu.com/ubuntu xenial/main i386 libhtml-template-perl all 2.95-2
  Failed to connect to cn.archive.ubuntu.com port 443: Connection refused
Ign:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-server-5.7 amd64 5.7.24-0ubuntu0.16.04.1 [2,726 kB]          
Get:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 mysql-server all 5.7.24-0ubuntu0.16.04.1 [10.8 kB]                 
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libevent-core-2.0-5 amd64 2.0.21-stable-2ubuntu0.16.04.1 [70.6 kB] 
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2 [60.4 kB]                                 
Fetched 10.6 MB in 24s (431 kB/s)                                                                                                              
W: Duplicate sources.list entry http://cn.archive.ubuntu.com/ubuntu xenial-updates Release
Preconfiguring packages ...
Selecting previously unselected package mysql-server-core-5.7.
(Reading database ... 601016 files and directories currently installed.)
Preparing to unpack .../mysql-server-core-5.7_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package libevent-core-2.0-5:amd64.
Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...
Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server-5.7.
Preparing to unpack .../mysql-server-5.7_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...
Unpacking libhtml-template-perl (2.95-2) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.24-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu21.10) ...
Setting up mysql-server-core-5.7 (5.7.24-0ubuntu0.16.04.1) ...
Setting up libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.24-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Setting up libhtml-template-perl (2.95-2) ...
Setting up mysql-server (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.10) ...
Processing triggers for ureadahead (0.100.0-19) ...
W: Duplicate sources.list entry http://cn.archive.ubuntu.com/ubuntu xenial-updates Release



wang@wang:~$ apt-get install mysql-client
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
wang@wang:~$ sudo apt-get install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mysql-client is already the newest version (5.7.24-0ubuntu0.16.04.1).
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-112 linux-headers-4.4.0-112-generic linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-headers-4.4.0-119
  linux-headers-4.4.0-119-generic linux-headers-4.4.0-121 linux-headers-4.4.0-121-generic linux-headers-4.4.0-124
  linux-headers-4.4.0-124-generic linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-headers-4.4.0-128
  linux-headers-4.4.0-128-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic linux-headers-4.4.0-133
  linux-headers-4.4.0-133-generic linux-headers-4.4.0-134 linux-headers-4.4.0-134-generic linux-headers-4.4.0-137
  linux-headers-4.4.0-137-generic linux-image-4.4.0-112-generic linux-image-4.4.0-116-generic linux-image-4.4.0-119-generic
  linux-image-4.4.0-121-generic linux-image-4.4.0-124-generic linux-image-4.4.0-127-generic linux-image-4.4.0-128-generic
  linux-image-4.4.0-130-generic linux-image-4.4.0-133-generic linux-image-4.4.0-134-generic linux-image-4.4.0-137-generic
  linux-image-extra-4.4.0-112-generic linux-image-extra-4.4.0-116-generic linux-image-extra-4.4.0-119-generic
  linux-image-extra-4.4.0-121-generic linux-image-extra-4.4.0-124-generic linux-image-extra-4.4.0-127-generic
  linux-image-extra-4.4.0-128-generic linux-image-extra-4.4.0-130-generic linux-image-extra-4.4.0-133-generic
  linux-image-extra-4.4.0-134-generic linux-image-extra-4.4.0-137-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 366 not upgraded.
W: Duplicate sources.list entry http://cn.archive.ubuntu.com/ubuntu xenial-updates Release




wang@wang:~$ sudo apt-get install libmysqlclient-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-112 linux-headers-4.4.0-112-generic linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-headers-4.4.0-119
  linux-headers-4.4.0-119-generic linux-headers-4.4.0-121 linux-headers-4.4.0-121-generic linux-headers-4.4.0-124
  linux-headers-4.4.0-124-generic linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-headers-4.4.0-128
  linux-headers-4.4.0-128-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic linux-headers-4.4.0-133
  linux-headers-4.4.0-133-generic linux-headers-4.4.0-134 linux-headers-4.4.0-134-generic linux-headers-4.4.0-137
  linux-headers-4.4.0-137-generic linux-image-4.4.0-112-generic linux-image-4.4.0-116-generic linux-image-4.4.0-119-generic
  linux-image-4.4.0-121-generic linux-image-4.4.0-124-generic linux-image-4.4.0-127-generic linux-image-4.4.0-128-generic
  linux-image-4.4.0-130-generic linux-image-4.4.0-133-generic linux-image-4.4.0-134-generic linux-image-4.4.0-137-generic
  linux-image-extra-4.4.0-112-generic linux-image-extra-4.4.0-116-generic linux-image-extra-4.4.0-119-generic
  linux-image-extra-4.4.0-121-generic linux-image-extra-4.4.0-124-generic linux-image-extra-4.4.0-127-generic
  linux-image-extra-4.4.0-128-generic linux-image-extra-4.4.0-130-generic linux-image-extra-4.4.0-133-generic
  linux-image-extra-4.4.0-134-generic linux-image-extra-4.4.0-137-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libmysqlclient20 zlib1g zlib1g-dev
The following NEW packages will be installed:
  libmysqlclient-dev libmysqlclient20 zlib1g-dev
The following packages will be upgraded:
  zlib1g
1 upgraded, 3 newly installed, 0 to remove and 365 not upgraded.
Need to get 2,192 kB of archives.
After this operation, 11.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libmysqlclient20 amd64 5.7.24-0ubuntu0.16.04.1 [810 kB]
Ign:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zlib1g amd64 1:1.2.8.dfsg-2ubuntu4.1
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 libmysqlclient-dev amd64 5.7.24-0ubuntu0.16.04.1 [1,162 kB]
Ign:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-2ubuntu4.1
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zlib1g amd64 1:1.2.8.dfsg-2ubuntu4.1 [51.2 kB]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-2ubuntu4.1 [168 kB]
Fetched 2,192 kB in 4s (471 kB/s)    
W: Duplicate sources.list entry http://cn.archive.ubuntu.com/ubuntu xenial-updates Release
(Reading database ... 601220 files and directories currently installed.)
Preparing to unpack .../zlib1g_1%3a1.2.8.dfsg-2ubuntu4.1_amd64.deb ...
Unpacking zlib1g:amd64 (1:1.2.8.dfsg-2ubuntu4.1) over (1:1.2.8.dfsg-2ubuntu4) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Setting up zlib1g:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Selecting previously unselected package libmysqlclient20:amd64.
(Reading database ... 601220 files and directories currently installed.)
Preparing to unpack .../libmysqlclient20_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking libmysqlclient20:amd64 (5.7.24-0ubuntu0.16.04.1) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../zlib1g-dev_1%3a1.2.8.dfsg-2ubuntu4.1_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ...
Selecting previously unselected package libmysqlclient-dev.
Preparing to unpack .../libmysqlclient-dev_5.7.24-0ubuntu0.16.04.1_amd64.deb ...
Unpacking libmysqlclient-dev (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libmysqlclient20:amd64 (5.7.24-0ubuntu0.16.04.1) ...
Setting up zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4.1) ...
Setting up libmysqlclient-dev (5.7.24-0ubuntu0.16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
W: Duplicate sources.list entry http://cn.archive.ubuntu.com/ubuntu xenial-updates Release



wang@wang:~$ sudo netstat -tap | grep mysql
tcp        0      0 localhost:mysql         *:*                     LISTEN      20582/mysqld    



wang@wang:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
// 然后通过 show databases; 就可以查看当前的数据库。
// 我们选择 mysql数据库就行下一步操作,使用use mysql 命令
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

//显示当前数据库的表单:show tables
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> exit
wang@wang:~$

http://www.cnblogs.com/zhuyp1015/p/3561470.html
更详细的安装:
https://www.linuxidc.com/Linux/2018-05/152413.htm

win10下:

MySQL下载
(1)
在这里插入图片描述
(2)
在这里插入图片描述
(3)解压之后进入解压目录,如解压到C:\mysql-8.0.16-winx64则进入此目录下,创建my.ini并编辑:

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
 
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\\mysql-8.0.16-winx64
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=C:\\web\\sqldata
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

(4)找到命令提示符应用cmd,以管理员身份打开:

C:\WINDOWS\system32>cd C:\mysql-8.0.16-winx64
C:\mysql-8.0.16-winx64>cd bin
//初始化数据库
C:\mysql-8.0.16-winx64\bin>mysqld --initialize --console
2019-06-22T01:46:13.105446Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 9304
2019-06-22T01:46:13.107310Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
//输出的root用户默认密码p?q+a;sNt7ua,初次登陆时使用,且登陆之后进行操作的时候会提示修改此密码。
2019-06-22T01:46:55.716610Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: p?q+a;sNt7ua
2019-06-22T01:47:09.886529Z 0 [System] [MY-013170] [Server] C:\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed

//安装
C:\mysql-8.0.16-winx64\bin>mysqld install
Service successfully installed.

//启动服务
C:\mysql-8.0.16-winx64\bin>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。

C:\mysql-8.0.16-winx64\bin>mysql -u root -p
Enter password: ************             //密码即p?q+a;sNt7ua
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16

Copyright (c) 2000, 2019, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'wang';
Query OK, 0 rows affected (0.09 sec)

mysql> exit
Bye

C:\mysql-8.0.16-winx64\bin>mysql -u root -p
Enter password: ****   修改后的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.03 sec)

mysql>

另:

windows下安装MySQLdb,python访问mysql的支持库,如下安装失败,解决方法是通过安装windows安装包。
在这里插入图片描述

1、下载MySQL-python

在这里插入图片描述
2、下载完成,双击666,哦不对,双击exe安装。
3、检查是否安装成功,导入此模块没任何提示则成功了。
4、python3安装PyMySQL,pip安装即可。

Microsoft Windows [版本 10.0.17134.829]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\zsl>python
Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import MySQLdb
>>>

5、此时在pycharm中import MySQLdb还是报错找不到该模块的问题。
File->Settings->Project Interpreter:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
6、连接出现 Client does not support authentication protocol requested by server; consider upgrading MySQL client
参考:http://www.360kuai.com/pc/9189ecbb0e83fd5af?cota=3&sign=360_57c3bbd1&refer_scene=so_1

安装完mysql后, 用代码或者可视化工具连接mysql时, 如果出现"Client does not support authentication

protocol requested by server; consider upgrading MySQL client" 提示, 是因为mysql服务器要求的认证插件

版本与客户端不一致造成的.

我们只需要通过mysql命令连接到数据库后, 运行如下命令降级我们的plugin即可:

alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘你的新密码’

猜你喜欢

转载自blog.csdn.net/u010931295/article/details/85130823