我的学习历程是先接触的nosql而后接触的mysql,所以这里记下的只是初学的一些东西,没什么见地。
安装mysql并且初始化
查看有没有安装过:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 yum list installed mysql* rpm -qa | grep mysql* ``` 安装mysql 服务器端: ```c yum install mysql-server yum install mysql-devel ``` 数据库字符集设置 mysql配置文件/etc/my.cnf中加入default -character-set =utf8 启动mysql服务:service mysqld start或者/etc/init.d/mysqld start 创建root管理员: ```c mysqladmin -u root password root ``` 忘记密码: ```c service mysqld stop mysqld_safe --user=root --skip-grant-tables mysql -u root use mysql update user set password=password("root" ) where user="root" ; flush privileges; ``` 远程访问 >开放防火墙的端口号 >mysql增加权限:mysql库中的user表新增一条记录host为“%”,user为“root”: ```c insert into user (user,host,password) values ('root' ,'%' ,password('root' )) ; ``` >给插入的这个账户提供所有表的操作权限 ```c grant all privileges on *.* to root@'%' identified by 'root' ; flush privileges; ``` 导出指定库到本地的目录(例如mysql库)
mysqldump -u\(USER -p\) PASSWD
-h127.0.0.1 -P3306 --routines --default-character-set=utf8 --databases
mysql > db.sql mysql -u\(USER
-p\) PASSWD -h127.0.0.1 -P3306 --default-character-set=utf8 mysql
< db.table.sql 1 2 3 4 5 ### docker使用mysql ubuntu14.04升级mysql 5.5到5.7太痛苦了
wget
https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb dpkg -i
mysql-apt-config_0.8.12-1_all.deb apt-get update apt-get install
mysql-server //这一步提示已经是最新版本,失败 //清理 rm
-rf /var/lib/apt/lists/ mv /etc/apt/sources.list ~/ rm -rf
/etc/apt/ mv ~/sources.list /etc/apt apt upgrade apt update
//重建gpg的key wget -q -O -
https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32 gpg --armor
--export 3B4FE6ACC0B21F32 | apt-key add - docker pull
daocloud.io/library/mysql:5.7 mkdir -p /mnt/sda3/mysql/{data,logs}
docker run -d --name mysql -v /mnt/sda3/docker_mysql/data:/var/lib/mysql
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=password
daocloud.io/library/mysql:5.7 docker exec -it mysql bash cat >
/etc/mysql/my.cnf << EOF [mysqld] skip-grant-tables EOF
docker restart mysql mysql -h 127.0.0.1 -P 3306 ```