mysql: Não é possível iniciar corretamente no Ubuntu

1

Eu tenho o seguinte problema. Quando o mysql é iniciado como serviço, tudo funciona bem: por exemplo,

oleg: ~$ sudo service mysql start 
mysql start/running, process 9111
oleg: ~$

Mas quando estou iniciando pela linha de comando, nada funciona. A configuração em si não parece incorreta no caminho abaixo:

oleg: ~$ cat /tmp/tmpWtpvgM/etc/my.cnf 
[mysqld]
pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.sock



    oleg: ~$ /usr/sbin/mysqld --defaults-file=/tmp/tmpWtpvgM/etc/my.cnf
    --user=root 
2015-11-26 12:18:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
    --explicit_defaults_for_timestamp server option (see documentation for more details). 
2015-11-26 12:18:24 0 [Note] /usr/sbin/mysqld (mysqld 5.6.27-0ubuntu0.14.04.1) starting as process 8448 ... 

2015-11-26 12:18:24 8448 [Warning] One can only use the --user switch if running
    as root

    2015-11-26 12:18:24 8448 [Warning] Buffered warning: Changed limits:
    max_open_files: 1024 (requested 5000)

    2015-11-26 12:18:24 8448 [Warning] Buffered warning: Changed limits:
    table_open_cache: 431 (requested 2000)

    2015-11-26 12:18:24 8448 [Note] Plugin 'FEDERATED' is disabled.
    /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist 
2015-11-26
    12:18:24 8448 [ERROR] Can't open the mysql.plugin table. Please run
    mysql_upgrade to create it. 
2015-11-26 12:18:24 8448 [Note] InnoDB:
    Using atomics to ref count buffer pool pages 
2015-11-26 12:18:24 8448
    [Note] InnoDB: The InnoDB memory heap is disabled 
2015-11-26 12:18:24
    8448 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-11-26 12:18:24 8448 [Note] InnoDB: Memory barrier is not used

2015-11-26 12:18:24 8448 [Note] InnoDB: Compressed tables use zlib
    1.2.8 
2015-11-26 12:18:24 8448 [Note] InnoDB: Using Linux native AIO 
2015-11-26 12:18:24 8448 [Note] InnoDB: Using CPU crc32 instructions
    2015-11-26 12:18:24 8448 [Note] InnoDB: Initializing buffer pool, size
    = 128.0M 
2015-11-26 12:18:24 8448 [Note] InnoDB: Completed initialization of buffer pool 
2015-11-26 12:18:24 8448 [Note] InnoDB:
    Highest supported file format is Barracuda. 
2015-11-26 12:18:24 8448
    [Note] InnoDB: Log scan progressed past the checkpoint lsn 49463

2015-11-26 12:18:24 8448 [Note] InnoDB: Database was not shutdown
    normally!
2015-11-26 12:18:24 8448 [Note] InnoDB: Starting crash
    recovery. 
2015-11-26 12:18:24 8448 [Note] InnoDB: Reading tablespace
    information from the .ibd files... 
2015-11-26 12:18:24 8448 [Note]
    InnoDB: Restoring possible half-written data pages  
2015-11-26
    12:18:24 8448 [Note] InnoDB: from the doublewrite buffer... InnoDB:
    Doing recovery: scanned up to log sequence number 1600607 
2015-11-26
    12:18:24 8448 [Note] InnoDB: Starting an apply batch of log records to
    the database... InnoDB: Progress in percent: 48 49 50 51 52 53 54 55
    56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
    InnoDB: Apply batch completed 
2015-11-26 12:18:24 8448 [Note] InnoDB:
    128 rollback segment(s) are active. 
2015-11-26 12:18:24 8448 [Note]
    InnoDB: Waiting for purge to start 
2015-11-26 12:18:24 8448 [Note]
    InnoDB: 5.6.27 started; log sequence number 1600607 
2015-11-26
    12:18:24 8448 [Note] Server hostname (bind-address): '*'; port: 3308

2015-11-26 12:18:24 8448 [Note] IPv6 is available. 
2015-11-26 12:18:24
    8448 [Note]   - '::' resolves to '::'; 
2015-11-26 12:18:24 8448 [Note]
    Server socket created on IP: '::'. 
2015-11-26 12:18:24 8448 [ERROR]
    Fatal error: Can't open and lock privilege tables: Table 'mysql.user'
    doesn't exist

Ainda não foi possível encontrar como rodar o mysql no ubuntu 14.04 e na configuração personalizada: (

também, parece que não consigo chamar o comando /usr/bin/mysql_install_db , para configurar o banco de dados em um novo datadir

por exemplo.

oleg: /usr/share/mysql$ /usr/bin/mysql_install_db --verbose
--defaults-file=/home/oleg/testing/etc/my.cnf --basedir=/usr/share/mysql --user=root 
 FATAL ERROR: Could not find my-default.cnf

 If you compiled from source, you need to run 'make install' to copy
the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top level
of the extracted archive, or pass the --basedir option pointing to
that location.

oleg: /usr/share/mysql$
    
por Oleg 26.11.2015 / 11:28

3 respostas

1

Você provavelmente instalou pacotes mysql fornecidos por repositórios do Ubuntu. Eu recomendo que você instale mysql-apt-config ou baixe os arquivos DEB diretamente de Site de downloads do MySQL . Você vai encontrar o último 5.6.28 lá em vez da versão 5.6.27.

Uma vez que você instalar os pacotes mysql-community- *, você poderá inicializar o datadir e ser capaz de inicializar uma nova instância do mysqld em um datadir diferente.

sudo /usr/bin/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql

Então inicie o mysqld assim:

sudo /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql

Aqui está meu arquivo de configuração de amostra:

cat /etc/my.cnf 
[mysqld]
basedir=/usr
datadir=/srv/data
pid-file=/srv/data/mysqld.pid
port=3308
socket=/srv/data/mysql.sock

E para provar que está usando o dito datadir:

mysql> select @@datadir;
+------------+
| @@datadir  |
+------------+
| /srv/data/ |
+------------+
1 row in set (0.00 sec)

EDITAR: O erro do seu mysql_install_db pode estar relacionado ao erro # 70067 .

Solução rápida se você não quiser instalar nenhum pacote, você pode criar este arquivo e executar mysql_install_db novamente.

cat /usr/share/mysql/my-default.cnf 
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

Apenas certifique-se de usar - user = mysql e não - user = root para /usr/bin/mysql_install_db ou /usr/sbin/mysqld

    
por 27.12.2015 / 09:21
0

O problema está nas configurações. Substitua isto

pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.soc

com

pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.sock
    
por 26.11.2015 / 12:15
0

O MySql tem sua localização pré-compilada para procurar por arquivos e dados de configuração. Então, a sua melhor aposta é compilar o mysql da fonte para si mesmo, se você quiser personalizar tudo. Caso contrário, pode ser confuso.

De acordo com o seu arquivo my.cnf personalizado, seu novo datadir é datadir=/tmp/tmpWtpvgM/var , e eu acho que está vazio, e é por isso que você está recebendo este erro.

Você deve tentar mover seus dados mysql de sua localização padrão ( /var/lib/mysql ) para sua localização personalizada primeiro e então tentar iniciar o mysql.

Ou tente criá-lo assim:

mysql_install_db --user=mysql --basedir=/tmp/tmpWtpvgM --datadir=/tmp/tmpWtpvgM/var

Verifique e certifique-se da permissão apropriada do diretório.

Verifique o aviso que você recebeu: One can only use the --user switch if running as root

Então, execute os comandos como root user.

Aqui estão dois posts muito relevantes:

link link

    
por 27.12.2015 / 00:56

Tags