linuxでのmysqlのインストール

5411 ワード

ubuntu下mysqlインストール:
sudo apt-get install mysql-server mysql-client

ダウンロードが完了するまで[y/n]を選択してyを選択すればよい.インストールが完了すると、アカウントのパスワードを入力するように要求されます.Windowsの下と同じアカウントのパスワードを許可するのはrootを例にとります
wei@ubuntu:~$ mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> grant all on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit

プロファイルの変更:
#  my.cnf   
root@ubuntu:/home/wei# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
root@ubuntu:/home/wei# cd /etc/mysql
root@ubuntu:/etc/mysql# ls
conf.d      debian-start  my.cnf.fallback  mysql.conf.d
debian.cnf  my.cnf        mysql.cnf
root@ubuntu:/etc/mysql# vi my.cnf 
#     bind-address           = 127.0.0.1            

wei@ubuntu:/etc/mysql$ ls
conf.d      debian-start  my.cnf.fallback  mysql.conf.d
debian.cnf  my.cnf        mysql.cnf
wei@ubuntu:/etc/mysql$ cd mysql.conf.d/
wei@ubuntu:/etc/mysql/mysql.conf.d$ ls
mysqld.cnf  mysqld_safe_syslog.cnf
wei@ubuntu:/etc/mysql/mysql.conf.d$ vi mysqld.cnf 

#       bind-address           = 127.0.0.1
#    
#  mysql
root@ubuntu:/home/wei# sudo /etc/init.d/mysql restart
Restarting mysql (via systemctl): mysql.service.
#  ip
root@ubuntu:/home/wei# ifconfig
ens33     Link encap:Ethernet  HWaddr 00:0c:29:4c:2c:a8  
          inet addr:192.168.60.128  Bcast:192.168.60.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe4c:2ca8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21947 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10883 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:23672949 (23.6 MB)  TX bytes:1101847 (1.1 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:11840 (11.8 KB)  TX bytes:11840 (11.8 KB)

root@ubuntu:/home/wei# mysql -uroot -p -h192.168.60.128 -P3306
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

次にwindowでテストします.
Microsoft Windows [   10.0.16299.309]
(c) 2017 Microsoft Corporation。      。

C:\Users\Administrator>mysql -uroot -p -h192.168.60.128 -P3306
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


MySQLへのアクセスに成功しました.
もし、ERROR 2002(HY 000):Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2)
sudo chown -R mysql:mysql /var/lib/mysql

systemctl start mysqld



初期パスワードの表示
grep 'temporary password'  /var/log/mysqld.log 

2018-04-18T06:31:06.476857Z 1 [Note] A temporary password is generated for root@localhost: <9M2:p%B# set password=password("root") ;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.01 sec)

mysql> set password=password("root");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set password=password("root");
Query OK, 0 rows affected, 1 warning (0.01 sec)