macOS中安装完MySQL后如何配置 5C

已参考下列教程
https://www.cnblogs.com/xuyatao/p/6932885.html
https://blog.csdn.net/fghsfeyhdf/article/details/78799270

服务已可以正常开启

图片说明

另外请大神看一下环境变量的配置是否正确

图片说明

数据库链接信息配置完成后进行链接,报错如下

图片说明

2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found

使用mysql -u root -p登录mysql

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

经过查询得知为初始密码不对的访问问题,mysql的root用户不会使用安装时输入的密码?(安装时设置为a123456)

使用方案:

方案1:
更改mysql目录中的my-default.cnf文件,但是进了目录下发现没有此文件

图片说明

so~ 在[mysqld] 的配置项下添加 skip-grant-tables 方法失败
方案2:
使用sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

sudo mysql -u root mysql

到这报错如下
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

[1]+ Stopped sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking

方案再次失败

求解

5个回答

MySQL安装完之后会弹出一个窗口,里面提供了你首次登录时应该使用的密码,而不是你自己设置的那个,注意不要切屏太快,那个窗口很容易被忽视

mac上还是建议用homebrew来安装,特别好用

你这个是因为在mysql安装时候选择了版本8以上的密码加密选项,SHA2的方式对你的密码进行了加密。
而Navicat Premium并没有SHA相关插件。所以密码核对不上。
我刚遇到这个问题。
下面说说我的结论

Mysql 在8版本新加入了SHA加密方式,所以在没有相关加密插件的Navicat Premium无法解密密码并进行连接的。

所以在安装时候请选择

第二个加密方式 Use Legacy Password Encryption

如果点错了也不要紧,在系统偏好设置里面选择 mysql

图片说明

图片说明

点击Initialize Database就会弹出设置选项。

图片说明

重新设置密码,即可连接成功。


mysql服务未正常运行,或者socket文件路径在配置文件中设置不完整
https://www.cnblogs.com/wzg123/p/6723338.html

1、安装:sunyichaodeMacBook-Pro:~ sunyichao$ brew install mysql
2、开启mysql:mysql.server start
2、使用mysql的配置脚本:/usr/local/opt/mysql/bin/mysql_secure_installation //mysql 提供的配置向导
启动这个脚本后,即可根据如下命令提示进行初始化设置

sunyichaodeMacBook-Pro:~ sunyichao$ /usr/local/opt/mysql/bin/mysql_secure_installation //mysql 提供的配置向导
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: k //是否采用mysql密码安全检测插件(这里作为演示选择否,密码检查插件要求密码复杂程度高,大小写字母+数字+字符等)
Please set the password for root here. // 首次使用自带配置脚本,设置root密码

New password:

Re-enter new password:

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? [Y/n] Y //是否删除匿名用户
... Success!

Normally, root should only be allowed to connect from 'localhost'.This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y //是否禁止远程登录
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y //删除测试数据库,并登录
Dropping test database...
... Success!
Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y//重新载入权限表
... Success!

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...
sunyichaodeMacBook-Pro:~ sunyichao$

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Mac OS 下MYSQL 的mysql.sock问题

情况描述:安装在Mac下的MySQL。刚安装完MySQL可以运行可以使用。在使用完MySQL 后,我会通过系统偏好设置里的按钮关闭MySQL Server。然后过一段时间再使用时就会出现 不能通过/tmp/mysql.sock建立连接这样的提示。然后我去到/tmp目录下,发现不存在mysql.sock文件。 在重新安装MySQL后,在/tmp目录下会重新出现mysql.sock文件。下面是我的提问,希望大家能为我 解答: 1.为什么mysql.sock会消失,重新安装后又会出现 2.网上说MySQL的默认sock路径和Mac下是不一样的。这里我非常不明白。在安装的时候把 mysql.sock安装在Mac的默认sock路径下,然后启动MySQL时又从MySQL的默认路径下找sock, 我这样的理解对吗?求解释 3.我该如何解决该问题。感觉主要问题就是/tmp/mysql.sock会自己消失。如何解决这个问题呢?

如何在Mac OSX上安装php 5.6 mysql扩展

<div class="post-text" itemprop="text"> <p>I am trying to setup PHP 5.6 and one of the older sites that I work with needs the mysql extension which didn't install when I ran:</p> <pre><code>brew install php56 --with-fpm --with-mysql --with-httpd </code></pre> <p>It installed php56 and that's all working fine however it installed the mysqli extension but I need the mysql extension too.</p> <p>Is there a way to install this extension to my current php setup?</p> <p>Here is the currently installed php extensions that I have:</p> <pre><code>5.6 php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom exif fileinfo filter ftp gd gettext hash iconv intl json ldap libxml mbstring mongodb mysqli mysqlnd odbc openssl pcntl pcre PDO pdo_mysql PDO_ODBC pdo_sqlite Phar posix readline Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer wddx xdebug xml xmlreader xmlrpc xmlwriter xsl zip zlib [Zend Modules] Xdebug </code></pre> <p>Just wondering, thanks!</p> </div>

Mac OS X 10.14.3下如何给Python2.7.10安装MySQL-Python?

执行如下命令: $ brew install mysql-connector-c $ sudo pip install MySQL-python 执行第二条命令时报错 执行brew install mysql后,再执行sudo pip install MySQL-python,依然报错 _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = strlen(buf); ~ ^~~~~~~~~~~ 13 warnings generated. cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- Command "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-8Cd2sn/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-qJxJuk/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-8Cd2sn/mysql-python/

Mac上安装MySQL之后,使用桌面客户端连接不上!!急

我使用终端测试过是可以建库建表的,然后用桌面的客户端不行,换了2个客户端了 ![图片说明](https://img-ask.csdn.net/upload/201508/06/1438794897_953080.png) ![图片说明](https://img-ask.csdn.net/upload/201508/06/1438794913_771389.png)

关于mac mysql配置的问题

配置mysql appledeMacBook-Pro-2:~ apple$ /usr/local/mysql-5.7.15-osx10.11-x86_64/bin/mysqladmin -u root password 12345 报错:error: 'Access denied for user 'root'@'localhost' (using password: NO)' 调试的时候 输入mysql 出现报错 command not found 查阅资料后建立连接文件 ln -s /usr/local/mysql/bin/mysql /usr/bin 然后查阅资料发现 sudo ln -s /usr/local/mysql/bin/mysql /usr/bin 这条语句也不可以 alias mysql=/usr/local/mysql/bin/mysql 报错: ERROR 1045 (28000): Access denied for user 'apple'@'localhost' (using password: NO) 出现1045错误 感觉死循环了 求高手解答一下 谢谢!

安装 mysql2时出错: 未能构建 gem 原生扩展

<div class="post-text" itemprop="text"> <p>I am having some problems when trying to install <code>mysql2</code> gem for Rails. When I try to install it by running <code>bundle install</code> or <code>gem install mysql2</code> it gives me the following error:</p> <blockquote> <p>Error installing mysql2: ERROR: Failed to build gem native extension.</p> </blockquote> <p>How can I fix this and successfully install <code>mysql2</code>?</p> </div> <p>转载于:https://stackoverflow.com/questions/3608287/error-installing-mysql2-failed-to-build-gem-native-extension</p>

MacOS下 mysql 无法通过terminal启动

起因是在Spring boot中启动报错,没有找到本地数据库 1. terminal 输入 **mysql --version** > 弹出版本号 8.0.19 2. terminal 输入 **mysql.server start** 提示 > command not found: mysql.server 3. terminal 输入 **mysql** 报错 > ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO) 4. 可以手动在界面中开启或关闭mysql ![图片说明](https://img-ask.csdn.net/upload/202002/10/1581289159_236074.png)

macOS所有修改过的权限恢复为默认

小弟做开发,安装了下idea 找了一篇帖子安装教程,因为安装的时候需要修改一些权限, 之后就发现mysql中的数据库没有了read的权限,对macOS 中权限知道的真的太少了点, 网上找了一些方法都不行,现在是想MAC可不可以将我原来所有修改过的系统权限全部恢复成默认的?不想重新安装系统,每天都在使用,没有时间安装系统

无法连接到mysql docker镜像连接被拒绝

<div class="post-text" itemprop="text"> <p>I just replaced my old company computer for a new one(MACOS), download the projects and now Im trying to connect to mysql docker image but I always get </p> <blockquote> <p>dial tcp 127.0.0.1:3306: connect: connection refused</p> </blockquote> <p>In my old computer everything worked correctly but now I've this problem.</p> <p>My docker compose(Not showing all the content):</p> <pre><code>version: "3" services: mysql: image: mysql:5.6 ports: - "3306:3306" volumes: - mysql-data:/var/lib/mysql - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d environment: MYSQL_ROOT_PASSWORD: a LANG: C.UTF-8 adminer: image: adminer ports: - 8082:8080 nginx: build: ../docker-shared/nginx ports: - 443:443 volumes: - "./nginx_proxy_settings.conf:/etc/nginx/conf.d/nginx_proxy_settings.conf" volumes: mysql-data: </code></pre> <p>So if I do a <code>docker-compose up</code> everything works, you can check in the next image the Adminer is working with data: <a href="https://i.stack.imgur.com/gph2d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gph2d.png" alt="enter image description here"></a></p> <p><a href="https://i.stack.imgur.com/yMGRe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yMGRe.png" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/nKFrY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nKFrY.png" alt="enter image description here"></a></p> <p>This is my Golang code to connect to mysql:</p> <pre><code>func main() { dbConfig := mysql.NewConfig() dbConfig.User = "root" dbConfig.Passwd = "a" dbConfig.Addr = "mysql" dbConfig.DBName = "company_prod" db, err := sql.Open("mysql", dbConfig.FormatDSN()) if err != nil { panic(err) } defer db.Close() } </code></pre> <p>Do you know what Im doing wrong??</p> <p>Thank you</p> </div>

OSX安装Mamp,MySQL失败

<div class="post-text" itemprop="text"> <p>Im trying to start MAMP but keep getting an error when starting.</p> <p>"MySql Failed"</p> <p><strong>LOGFILE</strong></p> <pre><code>[Wed Dec 06 17:17:50 2017] [notice] Digest: generating secret for digest authentication ... [Wed Dec 06 17:17:50 2017] [notice] Digest: done [Wed Dec 06 17:17:50 2017] [notice] FastCGI: process manager initialized (pid 71586) [Wed Dec 06 17:17:50 2017] [notice] Apache/2.2.32 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.1.8 mod_ssl/2.2.32 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0 configured -- resuming normal operations [Wed Dec 06 17:18:23 2017] [notice] caught SIGTERM, shutting down [Wed Dec 06 17:18:26 2017] [notice] Digest: generating secret for digest authentication ... [Wed Dec 06 17:18:26 2017] [notice] Digest: done [Wed Dec 06 17:18:26 2017] [notice] FastCGI: process manager initialized (pid 71984) [Wed Dec 06 17:18:26 2017] [notice] Apache/2.2.32 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.1.8 mod_ssl/2.2.32 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0 configured -- resuming normal operations [Wed Dec 06 17:26:52 2017] [notice] caught SIGTERM, shutting down [Wed Dec 06 17:27:01 2017] [notice] Digest: generating secret for digest authentication ... [Wed Dec 06 17:27:01 2017] [notice] Digest: done [Wed Dec 06 17:27:01 2017] [notice] FastCGI: process manager initialized (pid 72234) [Wed Dec 06 17:27:01 2017] [notice] Apache/2.2.32 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.1.8 mod_ssl/2.2.32 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0 configured -- resuming normal operations [Wed Dec 06 17:27:20 2017] [notice] caught SIGTERM, shutting down [Wed Dec 06 17:27:23 2017] [notice] Digest: generating secret for digest authentication ... [Wed Dec 06 17:27:23 2017] [notice] Digest: done [Wed Dec 06 17:27:23 2017] [notice] FastCGI: process manager initialized (pid 72793) [Wed Dec 06 17:27:23 2017] [notice] Apache/2.2.32 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.1.8 mod_ssl/2.2.32 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0 configured -- resuming normal operations [Wed Dec 06 17:27:30 2017] [notice] caught SIGTERM, shutting down [Wed Dec 06 17:27:36 2017] [notice] Digest: generating secret for digest authentication ... [Wed Dec 06 17:27:36 2017] [notice] Digest: done [Wed Dec 06 17:27:36 2017] [notice] FastCGI: process manager initialized (pid 73208) [Wed Dec 06 17:27:36 2017] [notice] Apache/2.2.32 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.1.8 mod_ssl/2.2.32 OpenSSL/1.0.2j DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.24.0 configured -- resuming normal operations </code></pre> <p>I saw solutions on remove you MySQL content and so on. <code>rm /Applications/MAMP/db/mysql56/*</code></p> <p>This has not worked. </p> <p>Have also tried to restart it and <code>sudo killall -9 mysqld</code></p> <p>Any ideas? </p> </div>

Mysql超时错误处理

<div class="post-text" itemprop="text"> <p>I am getting data from a web service and some times mysql times out "mysql server has gone away" and the whole page crashes.Is there any way I can capture such kind of error and not show the user a blank screen with the error message but instead redirect to some other page ... (programming language used is PHP)</p> </div>

Mac系统安装mysql,终端登录报Access denied for user root

![图片说明](https://img-ask.csdn.net/upload/201512/02/1449030093_552988.png) 如图,mysql安装好了也running了,现在在终端运行的时候总是会报错,如图 ![图片说明](https://img-ask.csdn.net/upload/201512/02/1449030099_64925.png) 密码尝试过root和123456,还有直接enter也试过了,总是报错,求大神解答啊

mysql workbench左侧导航栏和系统面板字体太小

![图片说明](https://img-ask.csdn.net/upload/201812/02/1543740952_87718.jpg)![图片说明](https://img-ask.csdn.net/upload/201812/02/1543740802_721908.jpg) 眼睛要看瞎了 不要跟我说是设置里面改,没有用 可能是要配置某个文件吧 希望步骤详细明确一点,谢谢

创建了一个新的数据库和新的表,show tables显示表已存在,但是select查询或desc都显示表不存在。

求解答 刚刚安装的MySQL 8.0.16版本 创建了一个新的数据库和新的表,show tables显示表已存在,但是select查询或desc都显示表不存在 Server version: 8.0.16 MySQL Community Server 系统MacOS ``` mysql> show databases; +--------------------+ | Database | +--------------------+ | e | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> create database t; Query OK, 1 row affected (0.00 sec) mysql> CREATE TABLE ‘test_0’( -> ‘id’ int(11) unsigned NOT NULL AUTO_INCREMENT, -> ‘name’ varchar(80) NOT NULL, -> PRIMARY KEY (‘id’) -> ); ERROR 1046 (3D000): No database selected mysql> use t Database changed mysql> CREATE TABLE ‘test_0’( -> ‘id’ int(11) unsigned NOT NULL AUTO_INCREMENT, -> ‘name’ varchar(80) NOT NULL, -> PRIMARY KEY (‘id’) -> ); Query OK, 0 rows affected (0.02 sec) mysql> show tables; +--------------+ | Tables_in_t | +--------------+ | ‘test_0’ | +--------------+ 1 row in set (0.00 sec) mysql> desc test_0; ERROR 1146 (42S02): Table 't.test_0' doesn't exist mysql> ```

mac杀不掉mysqld的进程,求大神帮忙

apple:/ apple$ ps aux | grep mysqld apple 3191 0.0 0.0 2434840 772 s000 S+ 6:20下午 0:00.00 grep mysqld _mysql 3139 0.0 2.7 3096788 450528 ?? Ss 6:10下午 0:00.49 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid apple:/ apple$ killall -9 mysqld No matching processes belonging to you were found apple:/ apple$ killall -9 3139 No matching processes belonging to you were found apple:/ apple$ kill -9 3139 -bash: kill: (3139) - Operation not permitted

MySQL数据库无法在XAMPP Manager-osx中启动

<div class="post-text" itemprop="text"> <p>I downloaded XAMPP about a month ago and it was working just fine. Today I installed a voice recognition software and then restarted my computer. Ever since, MySQL won't start in my manager-osx application. It doesn't throw me an in the application log. This is what it says:</p> <pre><code>Stopping all servers... Stopping Apache Web Server... /Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh : httpd stopped Stopping ProFTPD... Checking syntax of configuration file /Applications/XAMPP/xamppfiles/proftpd/scripts/ctl.sh : proftpd stopped Restarting all servers... Starting MySQL Database... Starting Apache Web Server... /Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh : httpd started Starting ProFTPD... Checking syntax of configuration file /Applications/XAMPP/xamppfiles/proftpd/scripts/ctl.sh : proftpd started </code></pre> <p>Both my ProFTPD and my Apache Web Server are running. MySQL isn't. When I go to phpmyadmin, it throws me this error message.</p> <pre><code>#2002 - No such file or directory The server is not responding (or the local server's socket is not correctly configured). </code></pre> <p>Please help me. I have no idea what to do.</p> <p>UPDATE: </p> <p>After looking around the internet a bit, I found a similar problem a user had with MAMP, another user recommended killing the mysql process, what ever that means. Could this be a fix to my problem?</p> <p>UPDATE 2: </p> <p>I found the answer to my problem but I can't answer it yet. So here's the answer:</p> <p>1) Open terminal and type</p> <pre><code>sudo su </code></pre> <p>and then put in your password</p> <p>2) Then type </p> <pre><code>ps aux | grep mysql </code></pre> <p>(just copy and paste this)</p> <p>3) You will need to get the process id of mysql. There should be number near the top, something like 739 or 8827</p> <p>4) Kill the process using</p> <pre><code>kill -9 {process id} </code></pre> <p>this should look something like this: kill -9 739</p> <p>5) Restart MySQL in manager-osx</p> </div>

mac下tpcc-mysql make时报错 library not found for -l-lrt

下载tpcc-mysql后,进入src目录,执行 `make` **报错信息:** ``` cc load.o support.o \`mysql_config --libs_r\` -lrt -o ../tpcc_load ld: library not found for -l-lrt clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [../tpcc_load] Error 1 ```

mac mysql 如何查看建表语句

如果是window的navicat右键表对象信息中有sql的,但是mac的navicat没有 我想看建表语句跟字段注释。

PDO / MySQL / PHP / OS X:MySQL服务器在后续查询中消失了吗?

<div class="post-text" itemprop="text"> <p>I think this is an issue in code somewhere, but the code's so simple I'm not sure what it could be.</p> <p>I've verified wait_timeout is high enough and have gone through everything here: <a href="http://dev.mysql.com/doc/refman/5.1/en/gone-away.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/gone-away.html</a> without any success.</p> <p>This happens reproducibly on the second query executed in one script run so I'm sure it's a coding error.</p> <p>I created a really simple wrapper around the PDO class to have a singleton database handle:</p> <pre><code>&lt;?php class PDOWrapper { protected static $instance; protected $dbh; function __construct() { if ( is_null(static::$instance) ) { static::$instance = $this; $this-&gt;connect_to_db(); } } static function instance() { if ( is_null(static::$instance) ) { new static; } return static::$instance; } private function connect_to_db() { $db_info = array( 0 =&gt; array( 'hostname' =&gt; "Host", 'username' =&gt; "User", 'password' =&gt; "Pass", 'db' =&gt; "DB", ) ); //Try to connect to the database try { $dbh = new PDO('mysql:host=' . $db_info[0]['hostname'] . ';dbname=' . $db_info[0]['db'], $db_info[0]['username'], $db_info[0]['password'], array( PDO::ATTR_PERSISTENT =&gt; true, PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES =&gt; true )); } catch (PDOException $e) { log_message("Error connecting to DB!: " . $e-&gt;getMessage(), LOG_LEVEL_CRITICAL ); return false; } $this-&gt;dbh = $dbh; } public static function get_dbh() { if ( is_null(static::$instance) ) { new static; } return static::$instance-&gt;dbh; } } </code></pre> <p>I then use the wrapper like so:</p> <pre><code>function somefunc(){ $dbh = PDOWrapper::get_dbh(); $future_sth = $dbh-&gt;prepare("SELECT * FROM some_table"); $future_sth-&gt;execute(); $ret = $future_sth-&gt;fetchAll(PDO::FETCH_ASSOC); print_r($ret); $future_sth-&gt;closeCursor(); return $ret; } </code></pre> <p>I call this function repeatedly as part of an event loop. The first time it calls it, the print_r runs fine and it prints out the rows I expect to see.</p> <p>After the function has been executed once, however, I get the following:</p> <pre><code>Warning: Error while sending QUERY packet. PID=92871 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' </code></pre> <p>I don't know why it'd have "gone away". My my.cnf looks ok. Wait timeout is massive and this happens immediately as soon as I run the second query anyway. Any ideas?</p> <p>It doesn't look like anything is obviously wrong in the MySQL error log:</p> <pre><code>120925 12:48:46 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql 120925 12:48:46 [Warning] The syntax '--log' is deprecated and will be removed in a future release. Please use '--general-log'/'--general-log-file' instead. 120925 12:48:46 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive 120925 12:48:46 InnoDB: The InnoDB memory heap is disabled 120925 12:48:46 InnoDB: Mutexes and rw_locks use GCC atomic builtins 120925 12:48:46 InnoDB: Compressed tables use zlib 1.2.5 120925 12:48:46 InnoDB: Initializing buffer pool, size = 128.0M 120925 12:48:46 InnoDB: Completed initialization of buffer pool 120925 12:48:46 InnoDB: highest supported file format is Barracuda. 120925 12:48:46 InnoDB: Waiting for the background threads to start 120925 12:48:47 InnoDB: 1.1.8 started; log sequence number 2273680401 120925 12:48:47 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306 120925 12:48:47 [Note] - '0.0.0.0' resolves to '0.0.0.0'; 120925 12:48:47 [Note] Server socket created on IP: '0.0.0.0'. 120925 12:48:47 [Note] Event Scheduler: Loaded 0 events 120925 12:48:47 [Note] /usr/local/Cellar/mysql/5.5.25a/bin/mysqld: ready for connections. Version: '5.5.25a-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution </code></pre> </div>

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐