Mac系统安装MySQL及Navicat Premium

安装MySQL

一、下载dmg包安装
1、下载MySQL dmg 包, 从官网 : http://www.mysql.com/downloads/ 进入, 点击下方的DOWNLOADS : MySQL Community Server

这里写图片描述

选择dmg文件下载
这里写图片描述

接着, 会跳转到如下页面, 你只需要选择不登录,直接下载即可 

这里写图片描述

打开下载好的dmg文件,安装。

2、进入系统偏好设置,点击MySQL,开启MySQL服务

这里写图片描述

这里写图片描述

3、环境变量配置(windows也是这样run的。可以不配置, 但每次必须在msyql的安装目录下,执行mysql命令。)
在Finder的侧边栏中单击“应用程序”,然后在“实用工具”中,双击启动“终端”命令。
这里写图片描述

在终端中输入添加MySQL路径的命令:

普通权限

PATH="$PATH":/usr/local/mysql/bin

在终端登录到MySQL的命令如下:mysql -u root -p

这里写图片描述

如果显示如上图所示的内容,表示已经成功登陆MySQL服务器。

MySQL my.cnf配置文件解决中文乱码问题

1.在 /etc 新建 my.cnf 文件
因为private这个文件夹是隐藏的,可以打开终端使用命令 open /etc/ 打开文件

sudo vim my.cnf

2.将如下配置内容写入到文件中

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
#default-character-set=utf8
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port        = 3306
socket      = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id   = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
default-character-set=utf8 
#no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

3.保存文件esc退出编辑模式,:wq退出,再重新启动MySQL。

终端进行查看

 PATH="$PATH":/usr/local/mysql/bin
mysql -u root -p

输入修改后的密码

这里写图片描述

查看字符集

show variables like '%char%';

我这边显示的mysql字符集

+--------------------------+-----------------------------------------------------------+
| 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       | /usr/local/mysql-5.7.20-macos10.12-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.00 sec)

终端命令启动mysql

sudo /usr/local/mysql/support-files/mysql.server start

遇到的问题顺便在这里提下, 说不定能帮读者少走点弯路, 参考资料 http://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045

在终端直接输入 Mysql -u root -p , 弹出输入密码, 输入密码后就报如下错误

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如果输入 mysql -u root , 会显示另外一种错误

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方案:

安装时候弹出:

2016-06-30T03:14:00.243422Z 1 [Note] A temporary password is generated for root@localhost: lKXyE0O(qd4o

If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.

注意:临时密码就是lKXyE0O(qd4o

Mac OS X - 重置 MySQL Root 密码

您是否忘记了Mac OS 的MySQL的root密码? 通过以下4步就可重新设置新密码:

  1. 停止 mysql server. 通常是在 ‘系统偏好设置’ > MySQL > ‘Stop MySQL Server’

  2. 打开终端,输入:

sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables

  1. 打开另一个新终端,输入:

sudo /usr/local/mysql/bin/mysql -u root

注意:mysql>

UPDATE mysql.user SET authentication_string=PASSWORD(‘新密码’) WHERE User=’root’;

FLUSH PRIVILEGES;

\q

  1. 重启MySQL.

*以上方法针对 MySQL V5.7.9, 旧版的mysql请使用:UPDATE mysql.user SET Password=PASSWORD(‘新密码’) WHERE User=’root’;

这里写图片描述

有时候连接数据库会失败,可能是密码问题,这个操作需要多。

Navicat Premium连接的数据库时候记得选上(Save password)保存密码

安装Navicat Premium

Navicat Premium for Mac 11.1.8 介绍

Navicat Premium for mac是一个可多重连接的数据库管理工具,Navicat 的功能足以符合专业开发人员的所有需求,但是对数据库服务器的新手来说又相当容易学习。它可让你以单一程序同時连接到目前世面上所有版本的主流数据库并进行管理和操作,支持的数据库有: MySQL、SQL Server、SQLite、Oracle 及 PostgreSQL。让管理不同类型的数据库更加方便。

Navicat Premium 结合了其他 Navicat 成员的功能。有了不同数据库类型的连接能力,Navicat Premium 支持在 MySQL、SQL Server、SQLite、Oracle 及 PostgreSQL 之间传输数据。包括存储过程,事件,触发器,函数,视图等。

Navicat Premium 适用于三种平台 – Microsoft Windows、Mac OS X 及 Linux。它可以让用户连接本机或远程服务器、提供一些实用的数据库工具如数据模型工具、数据同步、结构同步、导入、导出、备份、还原及报表以协助管理数据。

百度网盘下载地址:点击下载Navicat Premium for Mac 11.1.8
百度网盘提取密码:2mwc

安装完毕后打开

1.安装后第一次打开会弹出此框要求你连接mysql。连接名随便填,password 默认为 root.

这里写图片描述

这里写图片描述

2.完成之后,进入主界面你会看到你刚看创建的Connection.

这里写图片描述

3.打开myServerSQL,你会发现里面有几个已经创建的数据库,这是系统自动帮你创建的,不用管他。右键新建数据库new Database

这里写图片描述
Default Character Set 选择utf8.
Default Collation 选择utf8_bin.
这样选择可以避免出现中文乱码出现。

4.接下来在我们刚才创建的数据库下建表。
右键->new table:

这里写图片描述

这里写图片描述

这里写图片描述

在这个表中,我建立了三个域,ID,adminName,password。
在此界面下可以选择类型,长度,小数点后长度,是否为空,和设置为主键等功能。

选中一个域后,还可以在界面底部设置其他属性,有默认值,Comment,Column Format等
这里我给ID设为自增长。

点击save:

这里写图片描述

创建成功。

特别注意,最后在使用JDBC连接数据库时url应当在后面加上?useUnicode=true&characterEncoding=UTF-8
如下:

public class ConnectDB {
    public static Connection getConnection() {
    Connection connection = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        //-----在url后面添加useUnicode=true&characterEncoding=UTF-8这些参数是为了让mysql数据库可以识别中文-----
        String url = "jdbc:mysql://localhost:3306/vote?useUnicode=true&characterEncoding=UTF-8";
        String username = "root";
        String password = "root";           
        try {
            connection = DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
    return connection;
      }
}

连接数据库时出现的问题:
这里写图片描述

我的解决办法是修改密码。在navicat下修改密码很简单

在User下找到与上面对应出异常的用户。这里是root@localhost
点击进入:
这里写图片描述

右键新建用户
在password 和 Confirm password 两项中填入root.
这里写图片描述

save即可解决问题。

  1. 在系统偏好 中,中止MYSQL服务.;
  2. cd/usr/local/mysql-…../bin
    sudo ./mysqld_safe–skip-grant-tables
  3. 登录MySQL;
    mysql
  4. 置空root用户的密码;
    mysql> update mysql.user set password=‘’ whereUser=’root’;
    mysql> flush privileges;
    mysql> quit
  5. 重新启动MySQL服务,
  6. 添加密码mysql> mysqladmin -u root -p password 123 密码改为123

参考链接:http://www.yiduoyu.com/87.html
参考链接:https://www.jianshu.com/p/326c1aaa1052

### 回答1: Navicat Premium 15是一款功能强大的数据库管理和开发工具,它提供了一个易于使用的界面,支持多种主流数据库系统MySQL、MariaDB、Oracle、SQL Server等。 首先,您需要下载Navicat Premium 15的安装程序,可以通过官方网站或者其他可信的软件下载网站进行下载。如果您已经拥有了安装程序,可以直接开始安装。 打开安装程序后,您会看到一个欢迎界面,点击“继续”按钮开始安装过程。接下来,您需要同意软件的许可协议,可以阅读并勾选同意。 在安装类型界面,您可以选择完整安装或自定义安装。建议选择完整安装,这样您将获得Navicat Premium 15的所有功能和组件。然后,点击“安装”按钮开始安装过程。 安装过程可能需要一些时间,请耐心等待。完成安装后,您会看到一个安装成功的提示界面。点击“完成”按钮关闭安装程序。 现在,您可以在开始菜单或桌面上找到Navicat Premium 15的图标,双击图标打开软件。首次打开Navicat Premium 15时,您需要输入您的许可密钥进行注册。如果您是试用用户,可以选择试用模式。 注册完成后,您将看到Navicat Premium 15的主界面。在此界面上,您可以进行数据库的连接、管理和开发工作。您可以使用界面上的菜单、工具栏和窗口选项卡来进行你想要的操作。 总之,Navicat Premium 15是一款功能强大且易于使用的数据库管理工具,您只需按照上述步骤进行安装和注册,即可开始使用。希望这些信息对您有所帮助。 ### 回答2: Navicat Premium 15 for Mac是一款功能强大的数据库管理工具。安装Navicat Premium 15 for Mac非常简单,您只需按照以下步骤操作即可。 1. 首先,您需要从Navicat官方网站上下载Navicat Premium 15 for Mac安装程序。确保您选择的是适用于Mac操作系统的版本。 2. 下载完成后,双击安装程序进行安装系统可能会提示您输入管理员密码以进行安装。 3. 在安装向导中,您可以选择安装位置和其他选项。根据您的个人偏好进行选择。默认情况下,Navicat安装在“应用程序”文件夹中。 4. 单击“继续”按钮后,开始进行安装过程。安装过程可能需要一些时间,请耐心等待。 5. 安装完成后,您可以在“应用程序”文件夹中找到Navicat Premium 15的图标。双击打开Navicat。 6. 第一次打开Navicat时,系统可能会提示您输入许可证密钥或激活Navicat。请确保您已购买并获得了有效的许可证密钥,并按照提示进行操作。 7. 输入许可证密钥后,Navicat将完成激活过程,并为您提供访问数据库的功能。 通过以上步骤,您就可以成功安装和激活Navicat Premium 15 for Mac,并开始使用这款强大的数据库管理工具了。如果您遇到任何安装或使用上的问题,可以参考Navicat官方网站提供的帮助文档或联系他们的技术支持团队进行咨询。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值