英文:
unable to connect docker mysql databse to codeigniter application
问题
I am using ubuntu 18.04. I have installed mysql server in docker. I am unable to connect mysql database to codeigniter project.
我正在使用Ubuntu 18.04。我已经在Docker中安装了MySQL服务器。我无法将MySQL数据库连接到CodeIgniter项目。
I have created mysqldb using following command
我使用以下命令创建了MySQL数据库:
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password
the database is running on docker. i am able to access via phpmyadmin.
数据库正在Docker上运行。我可以通过phpMyAdmin访问它。
This is my database.php
这是我的database.php文件:
$db['default']['hostname'] = '0.0.0.0:3306';
$db['default']['username'] = 'root';
$db['default']['password'] = '1234';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['port'] = '3306';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
When i try to access codeigniter application i am getting following error:
当我尝试访问CodeIgniter应用程序时,我遇到以下错误:
A Database Error Occurred
发生了数据库错误
Unable to connect to your database server using the provided settings.
无法使用提供的设置连接到数据库服务器。
Filename: core/Loader.php
文件名:core/Loader.php
Line Number: 346
行号:346
I tried to access mysql db using terminal. i got an error
我尝试使用终端访问MySQL数据库。我收到了一个错误消息:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:YES)
Can anyone help me to fix this issue.
有人可以帮助我解决这个问题吗?
Version
版本
mysql Ver 14.14 Distrib 5.7.28 and php 7.2
mysql版本:Ver 14.14 Distrib 5.7.28 和 php版本:7.2
Thank you.
谢谢。
英文:
I am using ubuntu 18.04. I have installed mysql server in docker. I am unable to connect mysql database to codeigniter project.
I have created mysqldb using following command
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password
the database is running on docker. i am able to access via phpmyadmin.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c6474ed3f9d mysql:8 "docker-entrypoint.s…" 17 seconds ago Up 14 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql_80
This is my database.php
$db['default']['hostname'] = '0.0.0.0:3306';
$db['default']['username'] = 'root';
$db['default']['password'] = '1234';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['port'] = '3306';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
When i try to access codeigniter application i am getting following error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I tried to access mysql db using terminal. i got an error
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Can anyone help me to fix this issue.
Version
mysql Ver 14.14 Distrib 5.7.28 and
php 7.2
Thank you.
答案1
得分: 1
将此部分更改:
$db['default']['hostname'] = '0.0.0.0:3306';
更改为:
$db['default']['hostname'] = '127.0.0.1:3306';
请注意,0.0.0.0不是有效的IP地址用于连接,请注意我还假设您的应用程序直接在主机上运行而不是在容器中。
将此部分更改:
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password
更改为:
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 --default-authentication-plugin=mysql_native_password
您不需要指定mysqld
命令,因为它已经是mysql
镜像的入口点。
英文:
change this:
$db['default']['hostname'] = '0.0.0.0:3306';
to:
$db['default']['hostname'] = '127.0.0.1:3306';
0.0.0.0 is not a valid IP address to connect, please note that I also supposed that your APP is running on the host directly not in a container
and change :
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password
to :
docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8 --default-authentication-plugin=mysql_native_password
you do not need to specify mysqld command since it is already the entrypoint in mysql image
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论