brew instalar mysql en mac os


Estoy tratando de configurar MySQL en mac os 10.6 usando Homebrew por brew install mysql 5.1.52.

Todo va bien y también tengo éxito con el mysql_install_db.
Sin embargo, cuando intento conectarme al servidor usando:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'

Obtengo:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' 
failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'

He intentado acceder mysqladmin or mysql using -u root -proot también,
pero no funciona con o sin contraseña.

Esta es una instalación nueva en una máquina nueva y, por lo que sé, la nueva instalación debe ser accesible sin una contraseña de root. Me también probado:

/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation

Pero también consigo

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Author: guaka, 2010-12-05

14 answers

Creo que uno puede terminar en esta posición con versiones anteriores de mysql ya instaladas. Tuve el mismo problema y ninguna de las soluciones anteriores funcionó para mí. Lo arreglé así:

Cervezas usadas remove & cleanup comandos, descargó el script launchctl, luego eliminó el directorio mysql en /usr/local/var, eliminó mi /etc/my.cnf existente (déjelo a usted, si se aplica) y launchctl plist

Se ha actualizado la cadena para la lista plist. Tenga en cuenta también que su directorio de script de seguridad alternativo será basado en la versión de MySQL que está instalando.

, Paso a paso:

brew remove mysql

brew cleanup

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

sudo rm -rf /usr/local/var/mysql

Entonces empecé desde cero:

  1. instalado mysql con brew install mysql
  2. Ejecutamos los comandos brew sugeridos: (ver nota: abajo)

    unset TMPDIR
    
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    
  3. Inicie mysql con el comando mysql.server start, para poder iniciar sesión en él

  4. Usó el script de seguridad alternativo:

    /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
    
  5. Siguió la sección launchctl de la salida del script del paquete brew tal as,

    #start
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    
    #stop
    launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    
  6. Boom.

¡Espero que eso ayude a alguien!

Nota: el bit --force en brew cleanup también limpiará barriles obsoletos, creo que es una nueva característica homebrew.

Note el segundo: un comentarista dice que el paso 2 no es requerido. No quiero probarlo, así que YMMV!

 605
Author: Lorin Rivers,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-19 14:40:54

Tenía el mismo problema. Parece que hay algo mal con las instrucciones de configuración o las tablas iniciales que se están creando. Así es como conseguí mysqld funcionando en mi máquina.

Si el servidor mysqld ya se está ejecutando en su Mac, deténgalo primero con:

launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

Inicie el servidor mysqld con el siguiente comando que permite a cualquiera iniciar sesión con permisos completos.

mysqld_safe --skip-grant-tables

Luego ejecute mysql -u root que ahora debería permitirle iniciar sesión con éxito sin contraseña. El siguiente comando debería restablecer todas las contraseñas de root.

UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;

Ahora, si mata la copia en ejecución de mysqld_safe y la inicia de nuevo sin la opción skip-grant-tables, debería poder iniciar sesión con mysql -u root -p y la nueva contraseña que acaba de establecer.

 42
Author: Alistair McMillan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-07 23:30:54

Aquí hay instrucciones detalladas que combinan deshacerse de todo MySQL de su Mac y luego instalarlo de la manera Brew como Sedorner escribió anteriormente:

Eliminar MySQL completamente por El Laboratorio Tecnológico

  • ps -ax | grep mysql
  • stop y kill cualquier proceso MySQL
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/var/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • editar /etc/hostconfig y eliminar la línea MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*
  • intenta ejecutar mysql, no debería funcionar

Brew instalar MySQL por usuario Sedorner de esta StackOverflow respuesta

  • brew doctor y corregir cualquier error
  • brew remove mysql
  • brew cleanup
  • brew update
  • brew install mysql
  • unset TMPDIR
  • mysql_install_db --verbose --user= whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
  • mysql.server start
  • ejecute los comandos que Brew sugiere, agregue MySQL a launchctl por lo que se inicia automáticamente en el inicio

mysql ahora debería funcionar y estar funcionando todo el tiempo como se esperaba

Buena suerte.

 41
Author: corysimmons,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:45

Si brew instaló MySQL 5.7, el proceso es un poco diferente al de las versiones anteriores. Para restablecer la contraseña de root, proceda de la siguiente manera:

sudo rm -rf /usr/local/var/mysql
mysqld --initialize

Se imprimirá una contraseña temporal en la consola y solo se puede usar para actualizar la contraseña raíz:

mysql.server start
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'my-new-password';" | mysql -uroot -pTEMPORARY_PASSWORD
 11
Author: mrucci,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-25 19:11:49

Bien, tuve el mismo problema y lo resolví. Por alguna razón el script mysql_secure_installation no funciona fuera de la caja cuando se utiliza Homebrew para instalar mysql, así que lo hice manualmente. En la CLI ingrese :

mysql -u root

Eso debería llevarte a mysql. Ahora haga lo siguiente (tomado de mysql_secure_installation):

UPDATE mysql.user SET Password=PASSWORD('your_new_pass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
DROP DATABASE test;
FLUSH PRIVILEGES;

Ahora salga y vuelva a mysql con: mysql -u root -p

 8
Author: Darren Newton,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-26 05:03:14

Acabo de tener el mismo problema. Si brew info mysql y sigues los pasos, parece que la contraseña de root debería ser new-password si no recuerdo mal. Estaba viendo lo mismo que tú. Este artículo me ayudó más.

Resultó que no tenía ninguna cuentas creadas para mí. Cuando inicié sesión después de ejecutar mysqld_safe e hice select * from user; no se devolvieron filas. Abrí MySQLWorkbench con el mysqld_safe en ejecución y agregué una cuenta root con todas las privs que esperaba. Esto está funcionando bien para mí ahora.

 8
Author: Mark,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-07 04:18:54

Si mysql ya está instalado

Detenga mysql completamente.

  1. mysql.server stop
  2. ps -ef | grep mysql
  3. kill [PID]

Eliminar archivos. Las instrucciones anteriores son buenas. Voy a añadir:

  1. sudo find /. -name "*mysql*"
  2. Usando su juicio, rm -rf estos archivos. Tenga en cuenta que muchos programas tienen controladores para mysql que no desea eliminar. Para por ejemplo, no elimine cosas en el directorio de una instalación de PHP. Eliminar cosas en su propio directorio mysql.

Instalar

Espero que tengas homebrew. Si no, descárgalo.

Me gusta ejecutar brew como root, pero no creo que tengas que hacerlo. Editar 2018: ya no puedes ejecutar brew como root

  1. sudo brew update
  2. sudo brew install cmake
  3. sudo brew install openssl
  4. sudo brew info mysql
  5. sudo brew install mysql --with-embedded; say done

Después

  1. sudo chown -R mysql /usr/local/var/mysql/
  2. sudo mysql.server start
  3. Crear usuarios en mysql ( http://dev.mysql.com/doc/refman/5.7/en/create-user.html ). Recuerde agregar una contraseña para el usuario root.
 6
Author: sudo rm -rf slash,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-05 10:34:55

Brew info mysql

mysql: stable 5.6.12 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.12 (9363 files, 353M) *
  Poured from bottle
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mysql.rb
==> Dependencies
Build: cmake
==> Options
--enable-debug
    Build with debug support
--enable-local-infile
    Build with local infile loading support
--enable-memcached
    Enable innodb-memcached support
--universal
    Build a universal binary
--with-archive-storage-engine
    Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
    Compile with the BLACKHOLE storage engine enabled
--with-embedded
    Build the embedded server
--with-libedit
    Compile with editline wrapper instead of readline
--with-tests
    Build with unit tests
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To reload mysql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Mysql.inicio del servicio

. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

O mysql-u root

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Estoy buscando una solución desde hace algún tiempo, pero no puedo resolver mi problema. Probé varias soluciones en stackoverflow.com pero no esto me ayuda.

 3
Author: Felipe Duardo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-27 23:09:48

TL; DR

Es posible que el servidor MySQL no se esté ejecutando después de la instalación con Brew. Pruebe brew services start mysql o simplemente mysql.server start si no desea que MySQL se ejecute como un servicio en segundo plano.

Historia Completa:

Acabo de instalar MySQL (estable) 5.7.17 en un nuevo MacBook Pro ejecutando Sierra y también obtuve un error al ejecutar mysql_secure_installation:

Securing the MySQL server deployment.

Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

¿Decir qué?

De acuerdo con la información de instalación de Brew, mysql_secure_installation debería pedirme que lo haga... asegure la instalación. Me pensé que el servidor MySQL podría no estar funcionando y con razón. Correr brew services start mysql y luego mysql_secure_installation funcionó como un encanto.

 2
Author: Nicholas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-16 21:21:24

Intente dando el comando Grant permission de mysql

 1
Author: XMen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-05 14:12:09

Ninguna de las respuestas anteriores (o cualquiera de las docenas de respuestas que vi en otros lugares) funcionó para mí al usar brew con la versión más reciente de mysql y yosemite. Terminé instalando una versión diferente de Mysql a través de brew.

Especificando una versión anterior diciendo (por ejemplo)

brew install mysql56

Funcionó para mí. Espero que esto ayude a alguien. Este fue un problema frustrante en el que sentí que estaba atascado para siempre.

 1
Author: toddmetheny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-22 22:53:15

Tuve el mismo problema después de intentar reiniciar mysql.

Utilizo los siguientes dos alias en mi .perfil para mayor comodidad

alias mysql-stop='launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
alias mysql-start='launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' 

Después de detener mysql y luego tratar de reiniciar experimenté el problema que estaba teniendo. Miré en la carga launchctl y estaba reportando un error "nothing found to load".

Después de una búsqueda rápida encontré este..

Http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/

Así que me actualizé mysql-start alias como sigue

alias mysql-start='launchctl load -w -F ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'

Esto resolvió mi problema que puede ser útil para usted.

 0
Author: Alexander Millar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-09 13:00:30

La "Ruta Base" para Mysql se almacena en /etc/my.cnf que no se actualiza cuando realiza la actualización de brew. Simplemente ábrelo y cambia el valor basedir

Por ejemplo, cambie esto:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.13

Para señalar la nueva versión:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.19

Reinicie mysql con:

mysql.server start
 0
Author: Bernhard Zürn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-25 19:20:02

Aquí está una actualización para MySQL 5.7

bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin17.0.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

#========================================
brew --version
Homebrew 1.7.6
Homebrew/homebrew-core (git revision eeb08; last commit 2018-09-27)
Homebrew/homebrew-cask (git revision c9f62; last commit 2018-09-27)

#========================================
mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for osx10.13 (x86_64) using  EditLine wrapper

#========================================
system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.13.3 (17D47)
      Kernel Version: Darwin 17.4.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: EdisonMacHomeBj
      User Name: Edison (edison)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Disabled
      Time since boot: 6 days 23:13
brew remove [email protected]
brew cleanup
mv /usr/local/var/mysql /usr/local/var/mysql.bak
brew install [email protected]
rm -rf /usr/local/var/mysql

#========================================
mysqld --initialize
2018-09-28T04:54:06.526061Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-28T04:54:06.542625Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2018-09-28T04:54:07.096637Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-28T04:54:07.132950Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-28T04:54:07.196824Z 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: 87cf2f10-c2da-11e8-ac2d-ba163df10130.
2018-09-28T04:54:07.224871Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-28T04:54:07.366688Z 0 [Warning] CA certificate ca.pem is self signed.
2018-09-28T04:54:07.457954Z 1 [Note] A temporary password is generated for root@localhost: kq3K=JR8;GqZ

#========================================
mysql_secure_installation -uroot -p"kq3K=JR8;GqZ"
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.


The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

VALIDATE PASSWORD PLUGIN can be used to test passwords
and 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: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

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 them. 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
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? (Press y|Y for Yes, any other key for No) : n

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

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
 0
Author: Edison,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-28 07:05:44