20220119のMySQLに関する記事は5件です。

Node.js 【MySQL 8.0 に接続できない。】

Node.js 【MySQL 8.0 に接続できない。】 DBからデータ取得ができずに詰まったので備忘録。 起きたこと node.jsのパッケージ使って、MySQL8.0に接続しようとするとエラー発生 Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client エラー:ER_NOT_SUPPORTED_AUTH_MODE:クライアントはサーバーから要求された認証プロトコルをサポートしていません。 MySQLクライアントのアップグレードを検討してください (Google翻訳) 原因 MySQL8.0のパスワード認証形式の違いが原因。 MySQL8.0の認証プラグイン caching_sha2_password (MySQL5.7までは、mysql_native_password) mysql> SELECT user, host, plugin FROM mysql.user; +------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | mysql.infoschema | localhost | caching_sha2_password | | mysql.session | localhost | caching_sha2_password | | mysql.sys | localhost | caching_sha2_password | | root | localhost | caching_sha2_password | +------------------+-----------+-----------------------+ 4 rows in set (0.00 sec) 解決策 root(user), localhost(host)の plugin を変更。 caching_sha2_password → mysql_native_password plugin変更 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; 特権を更新 flush privileges; 確認 mysql> SELECT user, host, plugin FROM mysql.user; +------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | mysql.infoschema | localhost | caching_sha2_password | | mysql.session | localhost | caching_sha2_password | | mysql.sys | localhost | caching_sha2_password | | root | localhost | mysql_native_password | +------------------+-----------+-----------------------+ 4 rows in set (0.00 sec) その後、DBからデータ取得が取得できるようになりました。 おわりに。 こちらの記事 mysql2 をインストールするという手もあるようです。 npm install mysql2 caching_sha2_password の状態でも接続できるようです。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

安裝 MySQL

安裝 MySQL tags: MySQL 1. Add MySQL APT repository in Ubuntu sudo apt update sudo apt install wget -y wget https://dev.mysql.com/get/mysql-apt-config_0.8.12- 1_all.deb sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb In the prompt, choose Ubuntu Bionic and click Ok 在提示中,選擇 Ubuntu Bionic 並單擊確定 The next prompt shows MySQL 8.0 chosen by default. Choose the first option and click OK 下一個提示顯示默認選擇的 MySQL 8.0。 選擇第一個選項,然後單擊確定 In the next prompt, select MySQL 5.7 server and click OK. 在下一個提示中,選擇 MySQL 5.7 服務器並單擊確定。 The next prompt selects MySQL5.7 by default. Choose the last otpion Ok and click OK 下一個提示默認選擇 MySQL 5.7。 選擇最後一個選項 On 並單擊 OK 2. Update MySQL Repository on Ubuntu Run the below command to update your system packages 運行以下命令來更新您的系統包 sudo apt-get update 3. Install MySQL 5.7 on Ubuntu 20.04 Linux machine sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* Hit the y key to start installation of MySQL 5.7 on Ubuntu 20.04 Linux. Reading package lists... Done Building dependency tree Reading state information... Done Selected version '5.7.35-1ubuntu18.04' (MySQL:repo.mysql.com [amd64]) for 'mysql-client' Selected version '5.7.35-1ubuntu18.04' (MySQL:repo.mysql.com [amd64]) for 'mysql-community-server' Selected version '5.7.35-1ubuntu18.04' (MySQL:repo.mysql.com [amd64]) for 'mysql-server' The following additional packages will be installed: libmecab2 libtinfo5 mysql-common mysql-community-client The following NEW packages will be installed: libmecab2 libtinfo5 mysql-client mysql-common mysql-community-client mysql-community-server mysql-server 0 upgraded, 7 newly installed, 0 to remove and 90 not upgraded. Need to get 51.6 MB of archives. After this operation, 315 MB of additional disk space will be used. Do you want to continue? [Y/n] y Enter and re-enter root password when prompted 出現提示時輸入並重新輸入 root 密碼 4.Secure MySQL 5.7 Installation on Ubuntu 20.04 sudo mysql_secure_installation Press Enter. When prompted for password, provide the root password set above. 按 Enter。 當提示輸入密碼時,請提供上面設置的 root 密碼。 Answer the prompts as below: Enter current password for root (enter for none): <Enter 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 There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Using existing password for root. Estimated strength of the password: 25 -------------------------------------- Change the password for root ? ((Press y|Y for Yes, any other key for No) : d 更改 root 的密碼? Remove anonymous users? [Y/n] Y 刪除匿名用戶? Disallow root login remotely? [Y/n] n 禁止遠程root登錄? Remove test database and access to it? [Y/n] Y 刪除測試數據庫並訪問它? Reload privilege tables now? [Y/n] Y 現在重新加載權限表? Thanks for using MariaDB! 5. 啟用 MySQL 遠程訪問 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 查找“bind_address ”行並更改如下: sql= # By default we only accept connections from localhost #bind-address = 127.0.0.1 bind-address = 0.0.0.0 保存文件並重啟mysql sql= sudo systemctl restart mysql 6. 重啟MySQL service mysql restart 7. 修改帳號權限、遠端連線 grant all ON *.* TO 'root'@'%' IDENTIFIED BY '12345678'; flush privileges; 參考連結 刪除MySQL 1. 首先先移除 mysql apt-get purge --auto-remove mysql-common mysql-server mariadb-server apt-get autoremove apt-get autoclean 2. 然後把設定檔刪掉 rm -rf /etc/mysql rm -rf /var/lib/mysql 3. 砍掉 mysql 使用者 killall -9 mysql (或 killall -9 mysqld) userdel mysql 參考連結
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

MySQLのGPGキー有効期限が切れて、公式リポジトリからインストール出来なくなった話

回避策 暫定と思われるキーをインポートしてから、MySQLインストールすることで回避出来た。 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # Ubuntu wget -q -O https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 | apt-keyadd- エラーメッセージ Public key for mysql-community-client-8.0.28-1.el7.x86_64.rpm is not installed Failing package is: mysql-community-client-8.0.28-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 参考
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Did you install mysqlclient?って聞かれたらどうすればいい?

目的 いつも通りDJangoRestframeworkでAPIの作成に励んでいて、ふとしたことから仮想環境をanacondaからvirtualenvに変更しようとして色々とインストールし直していた。その時に事件は起こった。 いつも通りpython manage.py runserverでローカルサーバーを起動しようとした。 するとこのようなエラーが出てきた。。 File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/models/base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/models/base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/models/options.py", line 207, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__ return getattr(self._connections[self._alias], item) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__ conn = self.create_connection(alias) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/utils.py", line 204, in create_connection backend = load_backend(db['ENGINE']) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/Users/Yuto/dev/api_practice/tinder_api/tinder-venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 17, in <module> raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? 。。。!?!? Did you install mysqlclient? mysqlclientはインストール済みニダ。。。。 解決策 mysqlclientがないのではなく、pymysqlをインストールする必要があるよう。 $ pip install pymysql さらにsettings.pyのある階層のinit.pyに下記のように記述する。 __init__.py import pymysql pymysql.install_as_MySQLdb() もう一度ローカルサーバーを立ち上げる $ python manage.py runserver January 12, 2022 - 17:59:32 Django version 3.2, using settings 'tinder_api.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. 参考 Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Javaでデータベースに接続する

はじめに この記事は独習JSP&サーブレット第3版に基づいて、データベースを勉強していた際に躓いた点をまとめた記事です。最新版のJDBCやデータベースを使用している人は、同じようなエラーで躓いていると思うので参考になれば嬉しいです。 環境 Tomcat 10.0 MySQL 8.0 MySQLドライバ(JDBC):mysql-connector-java-8.0.27 jspからデーターベースに接続する 以下のようにconnect.jspファイルからデータベースに接続するとする。 データソースの設定はcontext.xmlで行う。 connect.jsp <%@ page contentType="text/html;charset=UTF-8" import="java.sql.*, javax.naming.*, javax.sql.*" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>データベースへの接続</title> </head> <body> <% Context context = new InitialContext(); DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/database_name"); Connection db = ds.getConnection(); db.close(); %> データベースへの接続に成功しました。 </body> </html> context.xml <?xml version="1.0" encoding="UTF-8"?> <Context reloadable="true"> <Resource name="jdbc/database_name" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://localhost/database_name?serverTimezone=JST" username="user_name" password="password" maxTotal="4" maxWaitMillis="5000" maxIdle="2" validationQuery="SELECT count(*) FROM book"> </Resource> </Context> Connector/JというMySQL用のJDBC Driverのバージョンが8.0.23以上を用いている人は次のようなエラーが発生していると思う。 Caused by: java.time.zone.ZoneRulesException: Unknown time-zone ID: JST 解決方法はcontext.xmlのタグ<Rerouce>にあるurlを以下のように変更すればいい。 url="jdbc:mysql://localhost/database_name" データベースにアクセスできるユーザーの設定方法 database_nameというデータベースにアクセスするためのアカウントを新規作成する. mysql> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password'; ユーザー名とパスワード以外にもlocalhostの部分も入力しないといけないので注意。 このアカウントに権限を与えるためには、GRANT命令を使う。 mysql> GRANT ALL ON database_name.* TO 'user_name'@'localhost'; ここでもlocalhostを忘れずに入力しないと次のようなエラーが発生する。 ERROR 1410 (42000): You are not allowed to create a user with GRANT おわりに 勉強する際は、最新版をインストールすると躓く。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む