Ubuntu
① sudo apt-get install mysql-server
安装过程中设置密码,如果为提示设置密码
输入$mysql -u root -p,会显示
zxx@DESKTOP-G716AO3:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
因此,需要设置root密码
1.cat /etc/mydql/debian.cnf,记录下其中的user和password字段内容
2.$mysql -u user字段内容 -p
输入password字段内容,以debian的配置登入mysql
3.mysql>
>use mysql;
>select host,user,plugin,authentication_string from user; #root用户的plugin为auth_socket,密码为空
>update user set plugin="mysql_native_password",authentication_string=password('新密码') where user="root";
4.>flush privileges;
5.$mysql -u root -p并以新密码登入mysql;
Centos
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
安装成功后重启mysql服务。
service mysqld restart
初次安装mysql,root账户没有密码。
[root@yl-web yl]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.01 sec)
mysql>
设置密码
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>
配置mysql
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set =utf8
远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';